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)
 create table from a query/view

Author  Topic 

Alex2011
Starting Member

18 Posts

Posted - 2011-04-27 : 16:23:44
Hi, how can I create a table directly from a view or query in SQL server 2000? thanks

Alex

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-04-27 : 16:38:20
You can use SELECT INTO. Here's an example:

SELECT *
INTO NewTableName
FROM TableOrViewName
...

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

mfemenel
Professor Frink

1421 Posts

Posted - 2011-04-27 : 16:39:46
Example:
select top 5 *
into dbo.test
from TableName

Mike
"oh, that monkey is going to pay"
Go to Top of Page

Alex2011
Starting Member

18 Posts

Posted - 2011-04-27 : 17:00:55
Thanks for your replies.

so I have to create a table first then insert the rows instead of create a table from a view directly? like

create table a
from
(select *
from view)
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-04-27 : 17:22:01
If you create the table first, use INSERT INTO...SELECT, rather than SELECT...INTO :

CREATE TABLE a(columns...)

INSERT INTO a
SELECT *
FROM TableOrViewName

SELECT...INTO will create the table on the fly, as long as it doesn't already exist.
Go to Top of Page

Alex2011
Starting Member

18 Posts

Posted - 2011-04-27 : 17:42:21
this is Great! You guys are awesome!thanks a lot!

this is exactly what i wanted.

Select *
Into test
from view
Go to Top of Page
   

- Advertisement -