Tag Info

Hot answers tagged

4

Since both PersonID and EmployeeID are candidate keys (and presumably will be implemented with uniqueness constraints) your proposed table design satisfies Boyce Codd Normal Form and therefore 3rd Normal Form as well. That doesn't necessarily make it a good idea. In principle, it's no bad thing to provide alternative identifiers for things but in this case I ...


2

In the table centresdevote you have a row where the value of objectid is 10. As you are trying to create a FOREIGN KEY CONSTRAINT there is a check that there is a matching value in the column objectid in the table prefectures for all the rows in centresdevote. In prefectures there is no row with objectid = 10. I suggest you read The PostgreSQL Documentation ...


2

Got to psql, issue \d your_table and look up the referenced table's name. If you set \set ECHO_HIDDEN on beforehand, you'll get a bunch of queries that produce the output, those you can reuse in your own discovery script. For example, on my test database these look like test=# \d tfk Table "test.tfk" Column │ Type │ Modifiers ...


2

It is not possible create a foreign key with a condition as you like. But you might use an intermediate table to simulate the condition. I call this table category_root. The category_root table will be updated only by triggers on category table. So you can create the foreign key between site table and category_root tables. No users must be have grants to ...


2

To enforce unique email addresses, I would remove all competing email columns and store them in one central email table for all active emails. And another table for deleted emails: CREATE TABLE users ( user_id serial PRIMARY KEY , username text UNIQUE NOT NULL , email text UNIQUE -- FK added below -- can also be NOT NULL ); CREATE TABLE email ( ...


1

One way to think of this would be that you have two classes of user which have slightly different rules: deleted and not deleted. Deleted users e-mails may clash, not deleted users e-mails must be unique. Because these two classes have different rules (i.e. constraints), instead of using a flag to indicate whether or not a user is deleted, I would duplicate ...


1

Aftee searching the Ideone FAQ, it seems that it uses Sqlite3 for the SQL language. Sqlite needs PRAGMA foreign_keys = ON; to enable foreign keys checks. As they say in their docs: SQLite Foreign Key Support : Assuming the library is compiled with foreign key constraints enabled, it must still be enabled by the application at runtime, using the PRAGMA ...



Only top voted, non community-wiki answers of a minimum length are eligible