First: specifying unique
and primary key is unnecessary in the table definition. A primary key is unique by definition.
Quote:
|
Originally Posted by FrOzeN89
in the Sales table I would like to create a constraint to limit (ItemNumber + TheDate) to be UNIQUE when combined
|
Create a unique index (or constraint):
Code:
create uniqe index unique_itemnumber_date on sales (ItemNumber,TheDate);
or
Code:
alter table sales add constraint
unique_itemnumber_date unique ((ItemNumber,TheDate);
Logically there is no difference between these two versions.
Some DBMS only allow a unique
constraint to be the target of a foreign key (but not a unique index).
Quote:
|
Originally Posted by FrOzeN89
Also, more importantly, is a constraint like this going to slow data entry down? I intend of having up to 2-3 million rows within this table.
|
There is a slight performance hit when creating an index, but that outweighs by far the advantages of having valid data in your datababase.
Quote:
|
Originally Posted by FrOzeN89
Would it be better to have more thorough code to prevent entering duplicates?
|
No, absolutely not. The only place to ensure these kind of constraints is in the database.
Btw: you have used the
AUTOINCREMENT which is
not standard SQL. It might be better to ask this question in the forum of your specific DBMS.