Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Change the name of the constraint

Author  Topic 

johnny1walker
Starting Member

17 Posts

Posted - 2012-03-15 : 19:36:11
Hi everybody..i got a problem
first
i add a constraint PK1
Use test
GO
ALTER TABLE tablo1 ADD CONSTRAINT PK1 PRIMARY KEY (a1)
GO

how do I
Change the name of the constraint as PK1 PK2 Table1 a1 area

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-03-15 : 19:42:36
Check out sp_rename.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

johnny1walker
Starting Member

17 Posts

Posted - 2012-03-15 : 20:51:13
how can I?

and

I tried these codes:
USE test
GO
EXEC sp_rename N'tablo1.PK1', N'PK2', N'a1';
GO
but gives an error message
Msg 15249, Level 11, State 1, Procedure sp_rename, Line 75
Error: Explicit @objtype 'a1' is unrecognized.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-03-15 : 21:06:37
please refer to the BOOKS ON LINE on the value of @objtype
http://msdn.microsoft.com/en-us/library/ms188351%28v=sql.90%29.aspx


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

johnny1walker
Starting Member

17 Posts

Posted - 2012-03-15 : 21:21:13
thanks.but.i just started to sql
I do not know how to.

I only want to do i
change PK1 to PK2
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-03-15 : 21:29:10
quote:
Originally posted by johnny1walker

thanks.but.i just started to sql
I do not know how to.

I only want to do i
change PK1 to PK2



Did you take a look at the link ? It tells you what are the value that you should pass into the @objtype parameter

It is ok if you are new to SQL. But when you not sure how to use a function or stored procedure on syntax or anything, refer to the Books OnLine. I am trying not to provide you the answer directly but pointing you to resources, help files where you can find the answer yourself.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

johnny1walker
Starting Member

17 Posts

Posted - 2012-03-15 : 22:45:51
i find script
Use test
GO
sp_rename 'PK1', 'PK2', 'OBJECT'
GO
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-03-15 : 22:49:44
Good


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -