Questions tagged [referential-integrity]

Referential integrity is a property of data which requires the value of an attribute/column of a relation table to exist as a value of another attribute/column in another relation table

For referential integrity to hold in a relational database, any field in a table that is declared a foreign key can contain either a null value, or only values from a parent table's primary key or a candidate key. In other words, when a foreign key value is used it must reference a valid, existing primary key in the parent table.

http://en.wikipedia.org/wiki/Referential_integrity

353 questions
2
votes
1 answer

MySQL InnoDB Changing Referential Actions ON DELETE CASCADE

Is there a faster way to add a CASCADE rule to an existing foreign key than dropping and adding the constraint? SET foreign_key_checks = 0; ALTER TABLE drop foreign key ...; ALTER TABLE add foreign key ...; SET foreign_key_checks = 1; Manual says,…
2
votes
2 answers

Can I use nHibernate with a legacy-database with no referential-integrity?

If I have a legacy database with no referential-integrity or keys and it uses stored procedures for all external access is there any point in using nHibernate to persist entities (object-graphs)? Plus, the SP's not only contain CRUD operations but…
AwkwardCoder
  • 24,893
  • 27
  • 82
  • 152
2
votes
1 answer

Checking Foreign Keys in MySQL

Is there a way to check foreign key integrity in MySQL? For example; is it possible to go through a database in information_schema checking each table for a constraint violation?
user1529891
2
votes
1 answer

Creating a check constraint for values in another table with nulls

I have two tables, A and B. The structure looks like this: CREATE TABLE A ( w int NOT NULL, x int NOT NULL, y int NOT NULL, CONSTRAINT PK_A PRIMARY KEY (w, x, y) ) CREATE TABLE B ( w int NOT NULL, y int NULL, z int NOT…
Dave
  • 53
  • 1
  • 6
2
votes
3 answers

null value in foreign key

I copied the following paragraph from http://msdn.microsoft.com/en-us/library/ms175464(v=sql.105).aspx A FOREIGN KEY constraint can contain null values; however, if any column of a composite FOREIGN KEY constraint contains null values, …
ZZZ
  • 3,574
  • 10
  • 34
  • 37
2
votes
1 answer

Composite Primary Key Cascading

Two fields, Building and Room, make up a unique primary composite key in my rooms table. The key validates and saves, etc. I have a BLANK Objects table which has three fields which will make it unique (again a composite primary key). The tables are…
StuckAtWork
  • 1,613
  • 7
  • 23
  • 37
2
votes
1 answer

How to approach deletion anomalies?

"There are circumstances in which the deletion of data representing certain facts necessitates the deletion of data representing completely different facts. The "Faculty and Their Courses" table described in the previous example suffers from this…
Travis J
  • 81,153
  • 41
  • 202
  • 273
1
vote
5 answers

unable to enforce referential integrity in Access

I've checked everything for errors: primary key, uniqueness, and type. Access just doesnt seem to be able to link the 2 fields i have in my database. can someone please take a look? http://www.jpegtown.com/pictures/jf5WKxKRqehz.jpg Thanks.
Tam N.
  • 2,687
  • 9
  • 30
  • 29
1
vote
3 answers

A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column:

First, thanks for taking the time to read this. I'm having some difficulties with trying to update a database using EF. I've used this same approach before on another project, so I'm thinking the issue is perhaps in the database, but I'm just not…
1
vote
2 answers

What's the best way to ensure referential integrity on a replicated database?

Using SQL SERVER 2005, I have a couple of questions on Replication and referential integrity. 1) Does Replication handle referential integrity? 2) If I do an Insert to Parent table and then to Insert to Child table, in one transaction, on Source DB…
1
vote
1 answer

db2 referential integrity problem

Situation is pretty serious, we have a table in DB2 on AS400 which has defined foreign key to another table, so we are entering record which have regular ID of referenced table so when we enter SQL insert through front end tool everything went fine.…
ante.sabo
  • 3,141
  • 6
  • 28
  • 36
1
vote
2 answers

Check referential integrity in stored procedure

I have a customer table and an order table in an sql server 2000 database. I don't want an order to be in the order table with a customerID that doesn't exist in the customer table so I have put a foreign key constraint on customerID. This all works…
1
vote
3 answers

Does creating a foreign key automatically mean referential integrity?

If I create a foreign key is referential integrity automatic? Do I have to set anything else to make cascading work? edit: for example, in postgres. I mean by automatic that I don't need to set anything else up to make RI work. Deletes. I am…
johnny
  • 19,272
  • 52
  • 157
  • 259
1
vote
1 answer

Django CheckConstraint not enforcing check on model field

I am using Django 3.2. Backend database used for testing: sqlite3 I have a model Foo: class Foo(models.Model): # some fields ... some_count = models.IntegerField() class Meta: models.constraints = [ …
1
vote
1 answer

Insert a constraint for two columns in sql

Hi everyone I created this table for a database CREATE TABLE IF NOT EXISTS compositions ( id INTEGER PRIMARY KEY AUTOINCREMENT, id_product INTEGER REFERENCES products(id), id_receipt INTEGER REFERENCES receipt(id), …