3
CREATE TABLE Persons
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
CONSTRAINT **uc**_PersonID UNIQUE (P_Id,LastName)
)
Nir Levy
  • 12,750
  • 3
  • 21
  • 38
  • 2
    That's just a part of the constraint name `uc_PersonID`. – jarlh Apr 29 '16 at 08:59
  • Yes, that's just prefix in the name. May be that's in your company's naming convention. Other may be suffix like: PersonID_cons1, Person_ID, Person_index1, .... – Pham X. Bach Apr 29 '16 at 09:02
  • 2
    I suppose uc means unique constraint. An internal enterprise notation to categorize the type of constraints – Joe Taras Apr 29 '16 at 09:03

1 Answers1

7

It is absolutely good practice to name your constraints (otherwise SQL Server will name them with a random name, which makes it really difficult to upgrade more than one system with a general upgrade script).

It is good practice to use a prefix to see what type of constraint this is.

Common are

  • UQ, UC or UK for unique constraint / unique key
  • FK for foreign key
  • PK for the primary key
  • CK for a CHECK constraint

UPDATE

And it is good practice to add the table's name to the constraint (to avoid ambiguities). In your case this was:

CONSTRAINT uc_Persons_PersonID UNIQUE (P_Id,LastName)

Btw (Naming convention): It is quite common to use table names in singular form (Person instead of Persons). Read here: Table Naming Dilemma: Singular vs. Plural Names

Community
  • 1
  • 1
Shnugo
  • 66,100
  • 9
  • 53
  • 114
  • I'd say the opposite, table names should be pluralis, because you store several persons in a table. Column name however, singularis. – jarlh Apr 29 '16 at 09:11
  • 1
    @jarlh :-) We might start a discussion, yeah! But jokes aside: It is opinion based (therefore the linked question is closed as opinion based). I think we can agree on one statement: Keep it consistent! The points collected in the highest voted answer there are rather convincing actually :-) – Shnugo Apr 29 '16 at 09:16