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
1
vote
1 answer

If I have a foreign key constraint of a table to itself, do I need to be careful when deleting the whole table?

I have a SQLite table that looks like this: CREATE TABLE myTable ( _id integer primary key autoincrement, ... ... /* some useful fields */ ... parent integer, FOREIGN KEY (parent) REFERENCES myTable (_id) ); Some of the…
Heinzi
  • 167,459
  • 57
  • 363
  • 519
1
vote
1 answer

Listing Cascade Update / Delete Referential Integrity Rules in an MS-Access Database?

In MS-Access I'm aware of referential integrity rules such as cascading updates and deletes and creating them using DDL. But after the tables have already been created, how can these be listed again?
leeand00
  • 25,510
  • 39
  • 140
  • 297
1
vote
2 answers

Help define referential integrity in Zend Framework 1.8.3 using Data Mapper model

I am unable to define referential integrity relationship using Zend Frameworks table relationships as documented in the manual. I have exhausted every possible configuration (so it seems), and now am facing the prospect of developing the application…
Tommy Cox Green
  • 633
  • 1
  • 4
  • 20
1
vote
2 answers

Does a foreign key make sense when I do not use Referential Integrity with On Delete/Update Cascade

I do not want the orders to be deleted when a customer is deleted. (On Delete Cascade) I use identity columns so I do not need On Update Cascade It should be possible to delete a customer table although there exist orders pointing/referencing to a…
Elisabeth
  • 20,496
  • 52
  • 200
  • 321
1
vote
1 answer

mysql foreign key reference from a composite key

I am creating an application that will handle and record when a student gets advised by a faculty member at a university and I need an effective way to structure the tables. My problem is coming from a lack of referential integrity, caused by the…
0
votes
1 answer

Setting default user in user table

I'm working on a database and I have a table called "Users", which store the sites user information (username, email and so on). The site has a forum and if a user that has posted something on the site deletes his account, I want "Deleted user" to…
holyredbeard
  • 19,619
  • 32
  • 105
  • 171
0
votes
2 answers

Rails and referential integrity

I would like to know if it's possible to write a migration instead of of the following raw SQL statement: execute <<-SQL ALTER TABLE records ADD CONSTRAINT fk_records_domains FOREIGN KEY (domain_id) REFERENCES domains(id) ON DELETE…
shoen
  • 11,845
  • 4
  • 22
  • 27
0
votes
3 answers

Maintaining referential integrity between a mobile client and a server

So I have a relatively simple system. A mobile client creates records in a sqlite database that I would like to have synced to a remote SQL server (that is shared with other mobile clients). So when I create a new record in the phone's sqlite table,…
JoeCortopassi
  • 5,083
  • 7
  • 37
  • 65
0
votes
5 answers

Can a SQL Server database schema always enforce its application's business logic by the use of foreign keys and check constraints alone?

Thank you for your earlier answers, but based on their feedback I have reformed the question. If the answer to the question is no, then can the data's integrity for enforced by any other means. I do not consider the use of stored procedures…
Duncan3142
  • 371
  • 2
  • 12
0
votes
2 answers

Import data from a single file into multiple Oracle tables

Is there a method to import data from a single file into multiple Oracle tables while maintaining the referential integrity?
user602599
  • 661
  • 11
  • 22
0
votes
1 answer

Play framework onetoone delete referential integrity

I get a referential integrity constraint violation for a JUnit Test. Using playframework and my two entities are as follows. @Entity public class User extends Model{ public String email; public String…
smk
  • 5,340
  • 5
  • 27
  • 41
0
votes
0 answers

How to maintain referential integrity in Postgres’s functions/stored procedures in light of schema changes

I don’t understand how to deal with schema changes and function definitions (which are by nature strings). For example, if I have a table called tablename1 and/or a column called columnname1, and these are referenced throughout my functions, how…
0
votes
1 answer

How to set foreign key with compound primary key in Kdb+?

It is sufficient documents about how to set foreign key, but few about how to set with compound primary/foreign key. I run following commands and the last 2 reported `length. How to set it correctly? t:([eid:1001 1002 1003]…
0
votes
1 answer

Referential Integrity does not work in N:N relation

This is ms create table script: It is a N:M relation between the SchoolclassCode and the Pupil table CREATE TABLE Schoolclasscode ( schoolclassId integer PRIMARY KEY AUTOINCREMENT NOT NULL ); CREATE TABLE SchoolclasscodePupil ( pupilId_FK …
msfanboy
  • 5,273
  • 13
  • 69
  • 120
0
votes
0 answers

Ruby on Rails => Launching rails model tests raises a database integrity error

I am currently developpig an app with ruby on rails. I have two models: House and Platform. Platform has a reference to House: ## house.rb class House < ApplicationRecord has_many :platforms, dependent: :destroy end ## platform.rb class Platform…