Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

alter script naming foreign keys Expand / Collapse
Author
Message
Posted Monday, July 7, 2008 1:53 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, March 21, 2014 10:22 AM
Points: 166, Visits: 387
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?
Post #529613
Posted Monday, July 7, 2008 1:56 PM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Sunday, November 23, 2014 12:50 AM
Points: 3,109, Visits: 11,515
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.
Post #529614
Posted Monday, July 7, 2008 1:58 PM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Friday, November 21, 2014 6:34 AM
Points: 6,259, Visits: 2,031
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
Post #529616
Posted Monday, July 7, 2008 2:09 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, March 21, 2014 10:22 AM
Points: 166, Visits: 387
awesome, thanks.
Post #529624
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse