December 7, 2007 at 9:55 am
I need to make a copy of a database but I only want to copy the first 4000 records in each table? Can someone help me with this?
December 7, 2007 at 10:04 am
backup the database, restore it, then for each table you need to decide what "first" is. There's no order by default in SQL Server.
ms_foreachtable is a stored procedure that will run for all tables. If you have a specific way to tell what the first 4000 rows are, you can run that.
Otherwise, maybe delete 1 row at a time while you have more than 4000 rows?
while (select count(*) from mytable) > 4000
begin
set rowcount 1
delete from mytable
set rowcount 0
end
Repeat
December 7, 2007 at 10:12 am
apologies I didn't word that correctly....I just need only 4000 records replicated vs. the 30,000 some records. These are patient records so I will need just 4000 patients and the data that corresponds with those records from each table....does that make sesne?
December 7, 2007 at 10:26 am
It makes sense, but there's not automated way to do a data cleanup like you're asking for. You either have to clean the data manually, or you need to toss the data and then go the other direction and automate data generation.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
December 7, 2007 at 11:16 am
Do you care which 4000?
You could insert 4000 PKs from the patient table into some new table, then set up a replication that filters based on those PKs. Or copy those items using DTS/SSIS to join with that table.
December 7, 2007 at 11:19 am
Nope don't care.....just need 4000. I'm a little green in my query writing so any assistance would be FABULOUS!
December 10, 2007 at 6:45 am
How can I set up a data replication filter? That seems to me the easiest way to accomplish this
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply