How to define a Unique Key Constraint that is composed of all columns in the table
Is there a shorthand similar to the wildcard symb开发者_StackOverflowol that allows me to define a unique key by which every column participates in the key? I'm using Postgres and I have a 30+ column table. Part of me thinks it's silly that I have to type out every single column name that will participate in the unique key.
I also think it would be awesome to not have to update the unique key if columns were added in the future.
I'm new to SQL, so please take it easy if this is a stupid question.
No maintenance-free shortcut. But right-click the table name in pgAdminIII, then select "Scripts", then "SELECT script". That will open a SQL window with a SELECT statement with every column listed and correctly quoted, if quotes are necessary.
I've been working on SQL database since the mid 1980s. I'm pretty sure I've never seen a table that had that many columns in a key. You might want to post the DDL for some more experienced eyes to evaluate.
DDL stands for Data Definition Language. It's the CREATE TABLE statement that defines the table. In pgAdminIII, right-click a table name, select "Scripts", then "CREATE script". pgAdminIII will open a SQL window with the CREATE TABLE statement (the DDL) in it. Copy it, edit your original question (or ask a new question), and paste that in.
精彩评论