Re: [SQL] database design SQL prob.
От | D'Arcy" "J.M." Cain |
---|---|
Тема | Re: [SQL] database design SQL prob. |
Дата | |
Msg-id | m1180J8-0000bFC@druid.net обсуждение исходный текст |
Ответ на | Re: [SQL] database design SQL prob. (Stuart Rison <stuart@ludwig.ucl.ac.uk>) |
Список | pgsql-sql |
Thus spake Stuart Rison > Currently, in postgreSQL, primary keys are created as a UNIQUE index on the > field(s) that form the primary key. > > This means that there is no difference between explicitely declaring a > PRIMARY KEY in your table definition or using the CREATE UNIQUE INDEX > command. Not completely accurate. Create some tables using both methods then run the following query. SELECT pg_class.relname, pg_attribute.attname FROM pg_class, pg_attribute, pg_index WHERE pg_class.oid = pg_attribute.attrelidAND pg_class.oid = pg_index.indrelid AND pg_index.indkey[0] = pg_attribute.attnum AND pg_index.indisprimary = 't'; This will give you a list of the primary keys if you declare them as primary at creation time. The ones created with just a unique index won't be displayed. While I am on the subject, anyone know how to enhance the above query to display all the fields when a complex primary key is defined? The above assumes that all primary keys are one field per table. -- D'Arcy J.M. Cain <darcy@{druid|vex}.net> | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 424 2871 (DoD#0082) (eNTP) | what's for dinner.
В списке pgsql-sql по дате отправления: