SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


alter script naming foreign keys


alter script naming foreign keys

Author
Message
Matthew Cushing
Matthew Cushing
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1193 Visits: 499
I'm trying to run a script that will put two keys onto a db. So far no problem. But when I go to look at the keys, the name of the fk is ALL Weird. Numbers, Letters, Underscores....

Is there a way to name the key so when I look at it, it makes sense?

ALTER TABLE table1
ADD FOREIGN KEY (UserID) REFERENCES User(userID);

the name of they key should be something like FKTable1_User, but it's messed up. any way to add in a param to name the key in the alter stmt?
Michael Valentine Jones
Michael Valentine Jones
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: General Forum Members
Points: 36274 Visits: 11933
You have to manually supply the name, instead of letting SQL Server pick one.

You can look up the format of the alter table statement in SQL Server Books Online.
noeld
noeld
SSC Guru
SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)

Group: General Forum Members
Points: 51374 Visits: 2052
Matthew Cushing (7/7/2008)
I'm trying to run a script that will put two keys onto a db. So far no problem. But when I go to look at the keys, the name of the fk is ALL Weird. Numbers, Letters, Underscores....

Is there a way to name the key so when I look at it, it makes sense?

ALTER TABLE table1
ADD FOREIGN KEY (UserID) REFERENCES User(userID);

the name of they key should be something like FKTable1_User, but it's messed up. any way to add in a param to name the key in the alter stmt?



ALTER TABLE table1
ADD CONSTRAINT FKTable1_User FOREIGN KEY (UserID) REFERENCES User(userID);





* Noel
Matthew Cushing
Matthew Cushing
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1193 Visits: 499
awesome, thanks.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search