Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Two questions regarding Tables
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

55 Posts

Posted - 03/26/2013 :  16:47:39  Show Profile  Reply with Quote
1. I am using SQL Express 2012. I downloaded the AdventureWorks2012 database. In the Object Explorer, I am in the AdventureWorks2012 database. Within the database, I have the 'tables' folder open showing all the tables. I am recreating the Person.CountryRegion table with 'III' appended to the end of the name. See below.

CREATE TABLE Person.CountryRegionIII
(CountryRC nvarchar(3) NOT NULL,
NameI nvarchar(50) NOT NULL,
ModifiedD datetime NOT NULL

The operation ran successfully, but I can't find the table in the tables folder. Where is this table and how do I refer to it?

2. Is it possible to clone a table? By that I mean create a copy of that table w/o having to manually create a new table, defining it, then copying data into that new table.

The Chadinator

1974 Posts

Posted - 03/26/2013 :  17:14:50  Show Profile  Visit chadmat's Homepage  Reply with Quote
Refresh the folder

Go to Top of Page

Flowing Fount of Yak Knowledge

2875 Posts

Posted - 03/26/2013 :  17:45:39  Show Profile  Reply with Quote
An answer to question 2, but use it at your own risk

INTO CloneTable
FROM ParentTable


Everyday I learn something that somebody else already knew
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 03/26/2013 :  17:47:25  Show Profile  Reply with Quote
You can "clone" a table a couple of different ways:

1. Right click on the table in SSMS object explorer, and select Script Table as -> Create To -> New Query Editor Window. Modify the script to change whatever you need (including constraint names etc.) and then run the script. That will create the new table.

2. Run a query such as this:[code]SELECT TOP (0) * INTO YourNewTableName FROM YourOldTableName. That will create a copy of the new table. You can omit the TOP (0) part if you want to insert the rows into the table as well.

There are differences between the two approaches - select into won't copy the keys but will keep the identity property etc. Investigate and use whichever suits your needs.
Go to Top of Page

Flowing Fount of Yak Knowledge

4614 Posts

Posted - 03/27/2013 :  17:31:47  Show Profile  Reply with Quote
#2 - There in no direct way to clone a table as you have described. But, there are pseudo ways that might work. You can select from the source table into a new one. That, as James said, won't include the keys, indexes, computed columns, etc.. For example:
INTO CloneTable
FROM Source

Of course you can script out the table, but then it won't have the data in it until you migrate the data.
Go to Top of Page
  Previous Topic Topic Next 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.03 seconds. Powered By: Snitz Forums 2000