ritesh gyanchandani ritesh gyanchandani - 2 years ago 65
SQL Question

What is the use of uc after constraint?

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)

Answer Source

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


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download