Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Not sure how to do this with a check constraint as I've only done simple checks before.The table has 2 columns InvoiceNo, PathNot allowed:99999 PathStringA99999 PathStringAAllowed:99999 PathStringA99999 PathStringBAllowed:99999 PathStringA99998 PathStringAAny ideas on how to do this?Thanks
georgev
Posting Yak Master
122 Posts
Posted - 2007-11-19 : 11:54:33
Declare a UNIQUE constraint on the columns...George<3Engaged!
qwertyjjj
Posting Yak Master
131 Posts
Posted - 2007-11-19 : 12:29:59
No, because both columns will not be unique.
Lamprey
Master Smack Fu Yak Hacker
4614 Posts
Posted - 2007-11-19 : 17:15:11
According to your example, YES!
CREATE TABLE #NoDups ( InvoiceNum INT NOT NULL, [Path] VARCHAR(50) NOT NULL)GOCREATE UNIQUE NONCLUSTERED INDEX UK_NoDup ON #NoDups (InvoiceNum, [Path])GOINSERT #NoDupsSELECT 99999, 'PathStringA'UNION ALL SELECT 99999, 'PathStringB'UNION ALL SELECT 99998, 'PathStringA'SELECT *FROM #NoDups-- FailsINSERT #NoDupsSELECT 99999, 'PathStringA'
cognos79
Posting Yak Master
241 Posts
Posted - 2007-11-19 : 17:16:15
if you are using stored proc to insert data into this table then you can make sure no duplicates are inserted using query.
georgev
Posting Yak Master
122 Posts
Posted - 2007-11-20 : 07:01:48
quote:Originally posted by qwertyjjj No, because both columns will not be unique.
The combination of both columns will be unique though..?Your example certainly suggests this!George<3Engaged!