Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

generating a "sample" database from SQL server?

Posted on 2013-01-20
5
Medium Priority
?
331 Views
Last Modified: 2013-01-22
Hi everyone:

I hope someone may be able to help me with this. I have a large database in SQL server with a dozen or more tables, and I want to create a small subset of that database such that -

(1) it contains only a subset of the tables, not all tables in the original SQL database;
(2) it contains only a random sample of the records, with the criteria that I'd specify (e.g. taskId = 1235 or taskId = 1354 or ...); and
(3) for tables that do not contain taskId as a field, it should be able to pull the records related to the taskId's that I specified (i.e. a 'join' operation).

Will this be possible, by any chance? If you can provide some pseudo codes (or sample SQL scripts), I'd really appreciate it.

Thank you very much!
0
Comment
Question by:someone-somewhere
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 29

Assisted Solution

by:chilternPC
chilternPC earned 750 total points
ID: 38799541
1) I would back up the database beofre starting :-)
2) install and use MySQL tools or workbench to access the tables
http://www.mysql.com/products/workbench/
3) I would make a DB copy and use the tools above to delete unwanted tables
you can also use the tools to generate quesries for you that you can copy
0
 
LVL 38

Accepted Solution

by:
Jim P. earned 750 total points
ID: 38799781
Since you posted in both MySQL and SQL Server 2008 that confuses the question from the outset.

Then you only want a portion of the tables of the production database, why?

I can understand a portion of the data easily enough. The way I would handle it is knowing the primary keys,

I'd create a temp table and then select from it for the keys I want.

Below is all aircode but a guidance to what you want to do.
if exists('tempdb..#temptbl')
begin
  drop table #temptbl
end

create table #temptbl(
     pk_ID     int
     ID_Num int identity(1,1))

insert into  #temptbl(pk_ID)
select pk_ID from OrigTbl

delete from #temptbl
where ID_Num not in (select ID_Num 
                             from  #temptbl where (ID_Num % 9) = 0) -- this gets you 10% of the record PKs.

Select * into otherDB.dbo.TblName where pk_ID in (select pk_ID from  #temptbl)

Open in new window

0
 

Author Comment

by:someone-somewhere
ID: 38802098
Thank you chiltenpc and jimpen, for your replies. Apologies for my mistake - I didn't mean to choose MySQL as one of the topics, and it is indeed just Microsoft SQL Server. Let me give it a try...
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 38806040
someone-somewhere,

Can I ask you why you gave a B grade?
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question