Performance Primary Keys creation

  • Hi,

    I am trying to figure out if there is a difference in performance between these two statements to create a primary key:

    ALTER TABLE Customer ADD PRIMARY KEY CLUSTERED ([iCustID] ASC)

    ALTER TABLE Customer ADD CONSTRAINT PK_ Customer PRIMARY KEY CLUSTERED (iCustID ASC)

    Is it the same thing?

    Thanks

  • Same thing. The only difference is in one you specify the PK name, in the other you get an automatically generated name. In all other aspects those two statements are identical.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • GilaMonster (5/1/2013)


    Same thing. The only difference is in one you specify the PK name, in the other you get an automatically generated name. In all other aspects those two statements are identical.

    As a matter of preference I always encourage architects/devs to ALWAYS explicitly name anything/everything they create that is namable. This will prevent auto-generated stuff from showing up as a difference if/when you compare databases (say across dev/test/prod systems). It also lets you know intelligently what the object really is by a good naming scheme.

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply