Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2012
    Posts
    15

    Unanswered: Change the name of the constraint

    Hi everybody..i got a problem

    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

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10

  3. #3
    Join Date
    Mar 2012
    Posts
    15

    sorry

    sorry.i just started to sql
    Change the name of whichever constraint
    C. Renaming an index
    D. Renaming an alias data type

    and..
    C. Renaming an index
    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.
    Last edited by johnny1walker; 03-15-12 at 21:19.

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Open the link I posted above and look at the @objtype argument
    An item of a type tracked in sys.objects. For example, OBJECT could be used to rename objects including constraints (CHECK, FOREIGN KEY, PRIMARY/UNIQUE KEY), user tables, and rules.
    George
    Home | Blog

  5. #5
    Join Date
    Mar 2012
    Posts
    15
    Quote Originally Posted by gvee View Post
    Open the link I posted above and look at the @objtype argument
    I tried these codes
    C. Renaming an index
    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.


    Is it difficult to change the constraint PK1 PK2?

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You need to actually read the link I sent you.

    The third argument should be @objtype, you are not using it this way.

    Have a look at the examples further down the page in the link I posted. Example C is a good one for you to focus on.

    Go back and read and try again
    George
    Home | Blog

  7. #7
    Join Date
    Mar 2012
    Posts
    15

    Smile

    i find scrpits
    Use test
    GO
    sp_rename 'PK1', 'PK2', 'OBJECT'
    GO

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •