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
Solved

generating a "sample" database from SQL server?

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Backup & Restore 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.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

856 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