SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 create table from a query/view
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Alex2011
Starting Member

18 Posts

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

Alex

tkizer
Almighty SQL Goddess

USA
36823 Posts

Posted - 04/27/2011 :  16:38:20  Show Profile  Visit tkizer's Homepage  Reply with Quote
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

USA
1421 Posts

Posted - 04/27/2011 :  16:39:46  Show Profile  Visit mfemenel's Homepage  Reply with Quote
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 - 04/27/2011 :  17:00:55  Show Profile  Reply with Quote
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)

Edited by - Alex2011 on 04/27/2011 17:02:09
Go to Top of Page

robvolk
Most Valuable Yak

USA
15659 Posts

Posted - 04/27/2011 :  17:22:01  Show Profile  Visit robvolk's Homepage  Reply with Quote
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 - 04/27/2011 :  17:42:21  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000