Syntax for UNIQUE constraint?

Ask a Question related to ASP, Design and Development.

  1. #1

    Default Syntax for UNIQUE constraint?

    I have an existing table:

    CREATE TABLE TestQuestions (
    qId int NOT NULL IDENTITY(1,1)
    CONSTRAINT PK_TestQuestions PRIMARY KEY NONCLUSTERED,

    testId int NOT NULL
    REFERENCES Tests(testId)
    ON DELETE CASCADE,

    objectiveId varchar (30) NULL

    qType int NOT NULL
    CONSTRAINT DF_TestQuestions_qType DEFAULT (0),
    )

    And I'd like to add the constraint:

    ALTER TABLE TestQuestions ALTER COLUMN objectiveId
    CONSTRAINT U_TestQuestions UNIQUE NONCLUSTERED (testId, objectiveId)

    Although obviously that's not the correct syntax. Could you tell me
    what *is* the correct syntax?

    Thanks,

    -- Rick

    Guinness Mann Guest

  2. Similar Questions and Discussions

    1. Unique Form inserting into many tables using unique id
      I have a Registration Form that have 3 steps. The data could be inserted into many (4) tables. Some data corresponding to a one table (the main or...
    2. Adding Constraint
      I need to add a constraint in some columns that aren't a FK or PK. I've already looked for it in the documentation but I haven't found yet. A...
    3. Adding UNIQUE constraint on NULL column
      I am trying to add a unique constraint on a column that can be null. The documentation states that null is treated as non equal values but I want...
    4. RAISEERROR from within constraint?
      It appears that RAISEERROR cannot be called from a constraint? If this is the case, how can I display a custom message when validation fails? I...
    5. Unique constraint
      > I need to create a unique contraint on a column (WO_number) but I can't use Then I don't understand how you are going to enforce uniqueness. ...
  3. #2

    Default Re: Syntax for UNIQUE constraint?

    Sorry about this article. I fumble-fingered the newsgroup. Should have
    gone to comp.databases.ms-sqlserver!

    -- Rick

    In article <MPG.19f76ed7563f5c3b989700@news.newsguy.com>,
    [email]GMann@dublin.com[/email] says...
    > I have an existing table:
    ....
    Guinness Mann Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139