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.
Author |
Topic |
rama108
Posting Yak Master
115 Posts |
Posted - 2013-11-01 : 15:43:45
|
Is there a way to script all keys from a table?Thanks. |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-11-01 : 16:05:45
|
Does this give you what you are looking for?SELECT c.NAME AS columnName, i.*FROM sys.indexes i INNER JOIN sys.COLUMNS c ON c.OBJECT_ID = i.OBJECT_IDWHERE OBJECT_NAME(c.object_id) = 'YourTableName' If you are trying to generate the scripts to create the keys/indexes, right click on the database name, Tasks-> Generate Scripts. There is an option that allows you to script indexes (along with the script for the table) |
|
|
rama108
Posting Yak Master
115 Posts |
Posted - 2013-11-01 : 20:38:43
|
James, Thank you for your response. May be you can help me with this. I have too many tables in the database. When I use the Import data wizard to import the data and the table structure in another database, it will not import the keys, column default values and the identity. I select Enable Identity, but it is not for actually importing the column as identity. So how do i use the wizard to import keys, indexes, identity and column defaults.Thank you. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-11-02 : 13:16:34
|
quote: Originally posted by rama108 James, Thank you for your response. May be you can help me with this. I have too many tables in the database. When I use the Import data wizard to import the data and the table structure in another database, it will not import the keys, column default values and the identity. I select Enable Identity, but it is not for actually importing the column as identity. So how do i use the wizard to import keys, indexes, identity and column defaults.Thank you.
you cant use wizard for that. you need to script and apply them separately. ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-11-02 : 13:45:09
|
If you've to do this in SSIS, you've task called Transfer SQL Server Objects which can also be used.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
rama108
Posting Yak Master
115 Posts |
Posted - 2013-11-02 : 16:02:07
|
Thanks. |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-11-02 : 16:55:50
|
quote: Originally posted by rama108 James, Thank you for your response. May be you can help me with this. I have too many tables in the database. When I use the Import data wizard to import the data and the table structure in another database, it will not import the keys, column default values and the identity. I select Enable Identity, but it is not for actually importing the column as identity. So how do i use the wizard to import keys, indexes, identity and column defaults.Thank you.
use the second method I described. That is to say, use "generate scripts" to script all your tables with keys, constraints; apply them to your target database. Then use import/export wizard. |
|
|
rama108
Posting Yak Master
115 Posts |
Posted - 2013-11-03 : 11:10:40
|
Thanks James. |
|
|
|
|
|
|
|