Skip to main content

New answers tagged

1 vote

Create table that has a sequence column counting from 1 for every different foreign key

A serial (or IDENTITY) column is not the right tool for your purpose. Those are meant to handle concurrent write access gracefully, and expressly not to produce a gapless sequence of row numbers, much ...
Erwin Brandstetter's user avatar
-1 votes

Is it necessary for a foreign key to be a primary key in another table? Why?

Actually, a foreign key may reference a unique key which allows NULLs that's why it is best for the child table to have the PK/FK on the same column.
William's user avatar
0 votes
Accepted

primary key referened by only single foreign key of another table among multiple tables that can reference it

There are no constraints to do that in any RDBMS I know... Traditional way is just go outside of the database. Have a field admin_or_customer in the account table and let client application to read ...
White Owl's user avatar
  • 876

Top 50 recent answers are included