September 3, 2005 at 9:44 am
I want to split a table in an existing DB into two tables. I know how to write script to create a new table, and another script to select all records, but what's the syntax to select all records from one table and use that select statement to make a new table?
THanks 🙂
Sam
September 3, 2005 at 11:19 am
is this what you're looking for ?!
CREATE TABLE NewTable
(colOne int,
colTwo varchar(50))
INSERT INTO NewTable
SELECT colOne, colTwo
FROM OldTable
**ASCII stupid question, get a stupid ANSI !!!**
September 3, 2005 at 1:38 pm
As simple as it looks, yes, that's all I needed. I hadn't done that before and was having a brain freeze. Appreciate it!
Sam
September 3, 2005 at 4:00 pm
I think what you are looking for is SELECT/INTO... it faster than any other method especially if you turn SELECT INTO/BULK COPY on...
It creates the table on the fly fut won't create the Primary Key... don't forget to add one...
SELECT colOne, colTwo
INTO NewTable
FROM OldTable
--Jeff Moden
Change is inevitable... Change for the better is not.
September 4, 2005 at 10:03 am
Might I point out that you'll want to also copy the primary key to the second table, most likely making it the clustered index, also I'd add the relation with on cascade delete.
September 6, 2005 at 7:26 am
THanks for the help. Will be working on this today!
Sam
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply