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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 UNIQUE combinations in tables

Author  Topic 

cathymomo
Starting Member

10 Posts

Posted - 2009-03-03 : 15:32:55
create table BudgetItem(
BINo integer not null,
BIYear integer DEFAULT '2005' not null check (BIYear>=1900),
BIAmt decimal DEFAULT '0' not null,
BIActual decimal DEFAULT '0' not null,
OrgNo integer not null,
ECNo integer not null,
PRIMARY KEY (BINo),
FOREIGN KEY (OrgNo) REFERENCES OrgUnit(OrgNo),
FOREIGN KEY (ECNo) REFERENCES ExpCat(ECNo));

Hi, the above is my table and I must make the combination of BIYear, OrgNo and ECNo Unique. Any answers on how to do this will be grately appreciated!!!!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-03-03 : 15:37:08
Just make that the composite primary key or you could use a unique constraint instead if you plan to have a surrogate key as the primary key, such as an identity column.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2009-03-03 : 16:14:58
since all three fields are numeric you can create primary key, but if you are planning to have milions of records in this table, i would recommend a primary key as identity column with integer type. You will have much faster results retrieving data from this table.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-03-03 : 16:27:15
I disagree that you'll have much faster results with an identity column over a composite key with 3 columns that are all integers.

slimt, please show us your tests that prove this.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -