Solved

copy table definition

Posted on 2001-06-11
5
586 Views
Last Modified: 2012-08-14
I need a sql statement that copies a table with all related stuff EXACLTY, but without the data to a new table name.  I has to work in sql server 7 and 2000 and must bring permissions and preferably indexes, defaults, etc with it.

Thanks in advance.
0
Comment
Question by:jrspano
5 Comments
 
LVL 2

Accepted Solution

by:
ykchakri earned 100 total points
ID: 6178909
You can run the following statement:
select * into table2 from table1
where 1 = 2

This is the quickest way of creating the table structure of table1 into table2.

But, if you want all other related stuff, such as permissions, then right click on the table in EM, select all tasks/generate SQL scripts and check all the options you require. Then modify this script to contain the new table name and run it.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6178915
I suggest that you look up the "generate script" in the "all tasks" menu of the table(s).
Cheers
0
 
LVL 1

Expert Comment

by:vim_asteya
ID: 6180082
see if this helps
create table t1(select * from mytable where 1=2)
t1- is the new table
mytable-is the table who's copy u want
this will copy the structure alone without any data
0
 
LVL 3

Author Comment

by:jrspano
ID: 6181010
thanks for all your input but unfortunatly it wont produce any dynamic output.  the script is static to my database.  I need something dynamic that will take a table I tell it to and make another table with the same table structure and permissions.
0
 
LVL 3

Author Comment

by:jrspano
ID: 6187907
i ended up using this, and not needing the user definitions. thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question