Hi, need help on coding.

I would like to create a table from another table, including relationships/index/keys.

I know I can do this:

Create Table New_Table
as (Select * from Old_Table)
where 1=2

but that would not include the relationships/index/keys. I wonder if it is possible to clone entirely by code. Many thanks.

Recommended Answers

All 3 Replies

Hi, need help on coding.

I know I can do this:

Create Table New_Table
as (Select * from Old_Table)
where 1=2

Yes. The above method does not include the relationships/index/keys.

You just generate CREATE script using SQL Server Management Studio and change table name and constraint names accordingly and execute it.

He is Right, You need to do in Management Studio and use a Create Script. Am not Sure you can do this programatically

The closest thing you can get realtively easily is Select Into but that won't preserve the entire table setup. What are you trying to accomplish?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.