adding unique keys

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • HandersonVA

    adding unique keys

    Would anyone please instruct how to prevent the duplicate record by
    setting the unique keys on the ms sql server? i've been checking the
    duplicate record as front-end and i found out if there is an internet
    delay or some other reasons, it has a chance to store the duplicated
    data into the database. so i realized it has to be done on the back-end
    side.
    for example, if i have three columns (office code, office id, office
    section) as a unique key, how can i setup this? thanks in advance.

  • SQL Menace

    #2
    Re: adding unique keys

    create a primary key or a unique constraint

    ALTER TABLE [dbo].[YourTable] WITH NOCHECK ADD
    CONSTRAINT [YourTable_PK] PRIMARY KEY CLUSTERED
    (
    [office code],
    [office id],
    [office section]
    ) WITH FILLFACTOR = 90 ON [PRIMARY]
    GO

    or

    ALTER TABLE dbo.YourTable ADD CONSTRAINT
    IX_YourTable UNIQUE NONCLUSTERED
    (
    [office code],
    [office id],
    [office section]

    ) ON [PRIMARY]

    Denis the SQL Menace



    HandersonVA wrote:
    Would anyone please instruct how to prevent the duplicate record by
    setting the unique keys on the ms sql server? i've been checking the
    duplicate record as front-end and i found out if there is an internet
    delay or some other reasons, it has a chance to store the duplicated
    data into the database. so i realized it has to be done on the back-end
    side.
    for example, if i have three columns (office code, office id, office
    section) as a unique key, how can i setup this? thanks in advance.

    Comment

    Working...