sql - Is having an identity primary key in addition to a composite unique constraint redundant? -


i have table has identity column primary key unique constraint on both identity column + second column:

create table variable (     variableid bigint identity(1,1) primary key nonclustered,     calcid bigint not null, ) create unique clustered index cl_calcid_variableid on variable(calcid,variableid) 

i have second table has identity primary key, 2 of same fields first table act foreign keys:

create table value (     valueid bigint identity(1,1) primary key nonclustered,     calcid bigint not null,     variableid bigint not null,     foreign key (calcid,variableid) references variable(calcid, variableid) ) create clustered index cl_calcid_variableid_valueid on value(calcid,variableid,valueid) 

is design redundant?

since variableid identity in first table, don't need foreign key have calcid , variableid in second table. thinking of building tables way though because combination of calcid+variableid "makes sense" describe unique record having identity column makes easier write queries update/delete single row - not sure if over-complicating design.

any thoughts appreciated, thanks.

edit: example data:

variableid  | calcid --------------------- 1           | 1 2           | 1 3           | 1 4           | 2 5           | 2  valueid | variableid    | calcid --------------------------------- 1       | 1             | 1 2       | 1             | 1 3       | 2             | 1 4       | 3             | 1 5       | 4             | 2 6       | 4             | 2 7       | 5             | 2  

as in cases, answer it depends.

keeping identity column surrogate key along side composite unique index idea when using key of table foreign key other tables. simplifies database connections , make joins easier write, read , maintain.

however, if table not referenced other tables, there not sense in adding surrogate key.

also, dnoeth wrote in comment, there no point of making composite unique index when of it's parts unique.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -