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 2005 Forums
 Transact-SQL (2005)
 Create table

Author  Topic 

sandeep43
Starting Member

11 Posts

Posted - 2011-07-18 : 08:19:44

Hi

How to create table and also copy its data structure from one database to another (with no data)?

i tired

create table PS_JOB as (select * from TEST.dbo.PS_JOB )


but it says
quote:

Incorrect syntax near the keyword 'as'.



please help me out

Regrds
Sandeep

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-07-18 : 08:27:07
[code]select top 0 * into YourNewTable from YourOldTable[/code]Alternatively, from SSMS object explorer, you can right click on the original table and select "Script Table as -> Create to -> To New Query Editor Window" to get the script for the original table. Then change the name, constraint names etc. and run the script.
Go to Top of Page

sandeep43
Starting Member

11 Posts

Posted - 2011-07-18 : 23:58:10
Hi

Thnks for reply, but i dont want to use select * into i want to use create table statement

Regards
Sandeep
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-07-19 : 00:17:11
But you used select * in your example.

Why don't you want to?
Go to Top of Page

sandeep43
Starting Member

11 Posts

Posted - 2011-07-19 : 00:44:35
Hi

i dont want to use

select * into


i can use select * from, my concern is there exists 2 databases say 1 and 2
in 1 i have a table called ABC, so same table should be created in 2 using create table statement, where only its data structured should be copied not data.

Regards
Sandeep
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-07-19 : 02:41:05
That's why sunita posted select top 0 *


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

sandeep43
Starting Member

11 Posts

Posted - 2011-07-19 : 02:50:56
no no, i have been telling that only i dont want to use

Select * into statement in project.


i want to use

Create table statement for creating tables from other database, how can i do that.

example in oracle we use

create table abc as (select * from databasename.schemaname.abc)

like this i want in sql
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-07-19 : 09:20:47
Sunita already showed you how it's done in SQL Server. No data will be copied, just the structure.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-07-19 : 09:30:16
quote:
Originally posted by sandeep43


Hi

How to create table and also copy its data structure from one database to another (with no data)?

i tired

create table PS_JOB as (select * from TEST.dbo.PS_JOB )


but it says
quote:

Incorrect syntax near the keyword 'as'.



please help me out

Regrds
Sandeep


But in ORACLE this syntax will create new table with data

Madhivanan

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

- Advertisement -