Solved

generating a "sample" database from SQL server?

Posted on 2013-01-20
5
314 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
  • 2
5 Comments
 
LVL 28

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now