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 |
kostbad
Starting Member
5 Posts |
Posted - 2013-12-15 : 16:40:26
|
I'm using "script table as", to copy the structure of a table. What i don't understand is why it leaves out some of the foreign keys!The table i'm trying to copy has 20 foreign keys, but the script creates a table with only 15. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-12-16 : 04:03:10
|
did you try using generate scripts wizard? Is it also creating scripts in same way?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
kostbad
Starting Member
5 Posts |
Posted - 2013-12-16 : 12:01:38
|
Yes, i did try that, with the same result. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-12-16 : 13:24:20
|
are you sure those foreign keys really do exist and is active? have a look at sys.foreign_keys view------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2013-12-16 : 14:06:12
|
Are you sure you are scripting the right table? The foreign key only gets scripted for one side of the relationship. Try scripting the other table to see if the FK gets scripted there.Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2013-12-16 : 15:09:15
|
another possibility is your scripting options excludes FKs.Tools | Options | Sql Server Object Explorer | ScriptingBe One with the OptimizerTG |
|
|
kostbad
Starting Member
5 Posts |
Posted - 2013-12-16 : 16:08:56
|
Thanks for your answers everyone.It's probably what tkizer said. Some F.K's must be scripted from the other tables.What i was actually trying to do at first was a bit complicated. I have duplicated a table called "customers" using "script as". Now i have a new table called, let's say "customers2". I want this table to have the same relationships with the other objects just like customers table has. I was hoping that "script as" would save me, but it's probably going to need a lot more planning and work to get it right. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-12-17 : 07:40:23
|
quote: Originally posted by kostbad Thanks for your answers everyone.It's probably what tkizer said. Some F.K's must be scripted from the other tables.What i was actually trying to do at first was a bit complicated. I have duplicated a table called "customers" using "script as". Now i have a new table called, let's say "customers2". I want this table to have the same relationships with the other objects just like customers table has. I was hoping that "script as" would save me, but it's probably going to need a lot more planning and work to get it right.
yep for that you can usehttp://visakhm.blogspot.in/2010/01/finding-cross-server-cross-db-object.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|