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
 General SQL Server Forums
 New to SQL Server Programming
 Select Statement

Author  Topic 

soori457
Yak Posting Veteran

85 Posts

Posted - 2008-02-20 : 05:12:24
In Emp Table I have some data, Now I want to create a new table Employee with same data.

with this statement I got into.

select * into Employee from Emp

with out into statement, I want to create a table
Is it possible



Suresh Kumar

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-02-20 : 05:15:43
Yes. Script out the Emp table, Make change to table name in script and execute script.

Then use INSERT...SELECT statement to fill the data.

In fact this is much preferred method than SELECT...INTO

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-20 : 05:35:07
quote:
Originally posted by soori457

In Emp Table I have some data, Now I want to create a new table Employee with same data.

with this statement I got into.

select * into Employee from Emp

with out into statement, I want to create a table
Is it possible



Suresh Kumar


As said,
Generate script of Emp
Rename Emp to Employee
Run the script

Then

Insert into Employee
Select * from Emp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-20 : 05:55:57
quote:
Originally posted by soori457

In Emp Table I have some data, Now I want to create a new table Employee with same data.

with this statement I got into.

select * into Employee from Emp

with out into statement, I want to create a table
Is it possible



Suresh Kumar


DO you mean you want to create table but should not populate it with data. then you can use same statement itself but like this

select top 0 * into Employee from Emp


Go to Top of Page

soori457
Yak Posting Veteran

85 Posts

Posted - 2008-02-21 : 00:01:45
How to Generate the Script of Emp Table

Please tell me.

Thanks in Advance

Suresh Kumar
Go to Top of Page

SusanthaB
Starting Member

14 Posts

Posted - 2008-02-21 : 00:13:37
Which version of SQL Server are you using? If its 2000, you can use Enterprise Manager tool. If its 2005, you can use SQL Server Management Studio.
Below steps are for SQL Server 2005. In Management Studio,
1. select the table from the object explorer.
2. right click on the table.
3. select "script table as".
4. select "CREATE TO".


Susantha Bathige
Senior DBA, Sri Lanka
Go to Top of Page

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-02-21 : 00:17:41
If you are using sql server 2005, then, right click on table for which you want to generate script.select "Script table as" option. Select Create To-->New Query Editor Window. It will generate script in query window. Rename table name to your desired table name "Employee". Run this script by pressing F5.Open new query window, and use
Insert into Employee
Select * from Emp

Hope you will be able to do.
Go to Top of Page
   

- Advertisement -