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
SSC Veteran
SSC Veteran (243 reputation)SSC Veteran (243 reputation)SSC Veteran (243 reputation)SSC Veteran (243 reputation)SSC Veteran (243 reputation)SSC Veteran (243 reputation)SSC Veteran (243 reputation)SSC Veteran (243 reputation)

Group: General Forum Members
Points: 243 Visits: 420
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
SSCertifiable
SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)

Group: General Forum Members
Points: 5766 Visits: 11771
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
SSCrazy Eights
SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)

Group: General Forum Members
Points: 9638 Visits: 2048
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
SSC Veteran
SSC Veteran (243 reputation)SSC Veteran (243 reputation)SSC Veteran (243 reputation)SSC Veteran (243 reputation)SSC Veteran (243 reputation)SSC Veteran (243 reputation)SSC Veteran (243 reputation)SSC Veteran (243 reputation)

Group: General Forum Members
Points: 243 Visits: 420
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