April 15, 2010 at 9:17 am
ALTER TABLE dbo.a
ADD FOREIGN KEY (id) REFERENCES dbo.b(id);
How can change the name of this key....after running this command SQL creates a foreign key constraint called FK_4A03EDD9...Can I change this name to something that makes since?
April 15, 2010 at 9:20 am
it's the full syntax for a constraint instead of the shortcut for a foreign key:
ALTER TABLE dbo.a
ADD CONSTRAINT FK_MyForeignKey FOREIGN KEY (id) REFERENCES dbo.b(id);
to rename a constraint that has a name you don't like,you use the proc sp_rename; it's like this:
sp_rename 'FK__GMACT__AACCOMPLT__3C5683AE','FK_MY_ACCOMPLISH'
Lowell
April 15, 2010 at 9:28 am
You can also right-click the constraint (in SSMS), and select rename and do it there.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
January 22, 2016 at 6:44 am
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply