473,395 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

Jul 20 '05 #1
1 25308
Try:

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

--
Hope this helps.

Dan Guzman
SQL Server MVP

-----------------------
SQL FAQ links (courtesy Neil Pike):

http://www.ntfaq.com/Articles/Index....partmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
-----------------------

"Guinness Mann" <GM***@dublin.com> wrote in message
news:MP************************@news.newsguy.com.. .

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

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Guinness Mann | last post by:
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)...
26
by: Agoston Bejo | last post by:
I want to enforce such a constraint on a column that would ensure that the values be all unique, but this wouldn't apply to NULL values. (I.e. there may be more than one NULL value in the column.)...
14
by: bolidev | last post by:
I'm new to SQL and can't figure out how to update my table (StoreItemStatus) that contains the current status for items in each store (STORE_KEY, ITEM_KEY, STATUS,...). I get updated status info...
6
by: Brian Basquille | last post by:
Just started learning SQL recently. But one thing i'm still not clear on is about altering relationships between tables after they've been created. Instead of creating a foreign key when the...
5
by: Kamil | last post by:
Hello What should I use for better perfomance since unique constraint always use index ? Thanks Kamil
4
by: Baoqiu Cui | last post by:
Hi, I was playing with MySQL (4.1.9) during the weekend, but noticed a minor problem and would like someone to explain this to me. Basically I could successfully create a table with one unique...
5
by: aj | last post by:
DB2 WSE 8.1 FP5 Red Hat AS 2.1 What is the difference between adding a unique constraint like: ALTER TABLE <SCHEMA>.<TABLE> ADD CONSTRAINT CC1131378283225 UNIQUE ( <COL1>) ; and adding a...
7
by: Brian Keating | last post by:
Hi there, Is it possible to add a unique constraint on two columns in a table, so that the constraint is a composite of the two? i.e. these two columns together should be unique...? i.e....
10
by: Laurence | last post by:
Hi there, How to differentiate between unique constraint and unique index? These are very similar but I cannot differentiate them? Could someone give me a hand? Thanks in advance
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.