Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL - Copy 1000 rows from one table to another

Status
Not open for further replies.

JJSEEMA

Programmer
Sep 25, 2008
2
US
i want to create a new table and copy first 1000 to the new table from old one How to do that.

I have
Code:
Create table New_Table (Item1, Item2) 
Insert Into New_Table (Item1, Item2)
Select Item1, Item2
 From Old_Table
 
Code:
Create table New_Table (Item1, Item2)
Insert Into New_Table (Item1, Item2)
Select TOP 1000 Item1, Item2
 From Old_Table
ORDER BY ???????????????

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Code:
SELECT TOP 1000 *
INTO NewTable
FROM OldTable

--or to be more precise (and new table is already defined)

INSERT INTO NewTable
SELECT TOP 1000 * FROM OldTable

"If I were to wake up with my head sewn to the carpet, I wouldn't be more surprised than I am right now.
 
you really must have an order by in the query to know you have the first 1000. Hopefully you have a filed that will indicate this either by being an insert date or an identity. Otherwise there is no way to guarantee you will get the first 1000 just a random 1000.

"NOTHING is more important in a database than integrity." ESquared
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top