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 RegrdsSandeep |
|
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. |
 |
|
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 statementRegardsSandeep |
 |
|
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? |
 |
|
sandeep43
Starting Member
11 Posts |
Posted - 2011-07-19 : 00:44:35
|
Hii dont want to use select * into i can use select * from, my concern is there exists 2 databases say 1 and 2in 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.RegardsSandeep |
 |
|
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. |
 |
|
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 |
 |
|
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. |
 |
|
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 RegrdsSandeep
But in ORACLE this syntax will create new table with dataMadhivananFailing to plan is Planning to fail |
 |
|
|