Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Creating tables from Select Queries

Author  Topic 

mattt
Posting Yak Master

194 Posts

Posted - 2002-04-05 : 08:35:57
Hi,

Is there an easy way to create a new table, populated from the results of a cross-table query?

I presume it's not quite as simple as
CREATE TABLE table_name (long winded SELECT statement)

ToddV
Posting Yak Master

218 Posts

Posted - 2002-04-05 : 08:53:08
quote:

Hi,

Is there an easy way to create a new table, populated from the results of a cross-table query?

I presume it's not quite as simple as
CREATE TABLE table_name (long winded SELECT statement)





Actually, it is really that simple. Use Select ..Into.

SELECT ..
INTO [TableName]
FROM ..
WHERE...



Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2002-04-05 : 10:44:35
A word of caution about SELECT INTO. I'm not sure how different that statement is from INSERT INTO...SELECT but I've had recent performance problems with INSERT INTO...SELECT. When running that statement, it broght all other queries to a near halt. I've read that doing a statement like this into a temp table will cause much locking in TempDB, and possibly slow down / stop other queries.

If this is a small table you are creating, you should have no problems. It's it's on the medium to large size (100k+ rows) be careful and throughly test it out. You'll probably be fine with anything under about 10k rows. I tried the INSERT INTO...SELECT with 4GB's of data (about 2.5 million rows). We gave up after 20 minutes. This was on a Dual Xeon 700 with 3.5GB's of RAM.

TEST THROUGHLY!!
Michael

Go to Top of Page
   

- Advertisement -