7

Had an exam today. One question disturbed me:

What can a table-level constraint do that a column-level constraint can't do?

My answer was that only a table-level constraint declaration permits setting up a composite primary key. I guess this is not the only difference. How could I have added to that?

14

You've forgotten about other types of constraint than primary key (also applies to unique, check, and foreign key constraints) but that's basically it.

A column-level constraint can only reference the column that it is declared next to. A table-level constraint can reference multiple columns.

| improve this answer | |
  • Hm, this is the SQL Server implementation, right? Postgres allows create table a (t int not null, u int not null check (u > t+v), v int null ); for example. No idea what the standard says. – ypercubeᵀᴹ Jun 15 '18 at 10:10
  • @ypercubeᵀᴹ - yep, for SQL Server. I've no idea of what the standard says either (or how other DBMSs address this) – Martin Smith Jun 15 '18 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.