Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Would I use a constraint?

Status
Not open for further replies.

R7Dave

Programmer
Oct 31, 2007
181
US
Hello

I would like to set up a database rule that would only allow unique entry of a certain field.

It is a field taht does not ned to be indexed.

Here is an example

PNum | Project Name
1 | Bookkeeping
2 | Contact Management
3 | Accounting

I don't want the user to be able to enter another project with the same project name (in this example, I don't want another row that will allow

4 | Bookkeeping

Would a constarint be used in this situation? What would the check constraint expression be?

Am I using the right tool for the job?

Thanks for any help

Dave
 
Books Online said:
CREATE TABLE doc_exc ( column_a INT)
GO
ALTER TABLE doc_exc ADD column_b VARCHAR(20) NULL
CONSTRAINT exb_unique UNIQUE
GO
EXEC sp_help doc_exc
GO
DROP TABLE doc_exc
GO

"NOTHING is more important in a database than integrity." ESquared
 
Look Up the keyword : UNIQUE

"If I were to wake up with my head sewn to the carpet, I wouldn't be more surprised than I am right now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top