Solved

generating a "sample" database from SQL server?

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

730 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