I want to create a foriegn key that references the primary key in another table. I am doing this using an alter statement. Strangely the name of the foreign key created is FK_BBB_Aid_1975C517 ?
I am working on a team and they are not strong on Sql. However they don't want the key to look like that, with the mysterious appended numbers at the end. Why is this happening? I need the foriegn key to have a name such as FK_Aid instead of the one mentioned above. Can someone help me to fix this? below is my Sql where I use the Alter statement to create the foreign key.
-----Also...This is how the tables are defined in Sql Server--- AAA Aid (PK, smallint, not null) Name (nvarchar(50), not null)
BBB BId (smallint, not null) AId (smallint, not null) ---------------------------------------
-- Here is my sql which alters the table
Alter Table [dbo].BBB ADD FOREIGN KEY [Aid] References AAA(Aid)
AppDevForMe
Participant
1396 Points
1327 Posts
Alter statement to creat foriegn key gives strange naming
Sep 20, 2011 06:07 PM|LINK
FParikh
Member
142 Points
31 Posts
Re: Alter statement to creat foriegn key gives strange naming
Sep 20, 2011 06:11 PM|LINK
Try the following statement and replace the constraintname with the name you want.
TabAlleman
All-Star
15571 Points
2700 Posts
Re: Alter statement to creat foriegn key gives strange naming
Sep 20, 2011 06:29 PM|LINK
SQL creates Key names like this when you don't specify a name.
To specify a name at the time you create the key, change your ALTER statement to something like this:
-- Here is my sql which alters the table
Alter Table [dbo].BBB ADD
CONSTRAINT [FK_Aid]
FOREIGN KEY [Aid]
References AAA(Aid)