Solved

generating a "sample" database from SQL server?

Posted on 2013-01-20
5
325 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 250 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 250 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

728 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