SQL Database Unique Field Question

Results 1 to 2 of 2

Thread: SQL Database Unique Field Question

  1. #1
    Join Date
    Dec 1969

    Default SQL Database Unique Field Question

    I posted this yesterday but got distracted so as to not figure it out. Here goes<BR><BR>Here is my scenario: <BR>I have a table with 6 fields. The Primary Key is an auto-incrementing field as there are no other fields that could be a PK. <BR><BR>Here is my question: <BR>Is it possible with SQL to make it so that the calculation of 4 fields in this table must be unique. This is needed so that data entry errors are avoided. <BR><BR>How would one do this in SQL? <BR><BR>Paul <BR><BR>thanks in advance <BR><BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default Unique constraint

    You can create a unique constraint, either when creating the table, or adding it afterward. Wiz<BR><BR>create table x(uk1 int,uk2 int,uk3 int,uk4 int,nk1 char,nk2 char,constraint unique_key unique(uk1,uk2,uk3,uk4))<BR><BR>or<BR><BR>alter table x add constraint unique_key unique(uk1,uk2,uk3,uk4)<BR><BR>The constraint name can be used if you wish to drop the constraint from the table<BR><BR>Alter table x drop constraint unique_key

Posting Permissions

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