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
0
votes
2 answers

Which table should be filled first with a minimum cardinality of 1..1 using referential integrity?

Say I'm using referential integrity and I have a relationship between two entity's (A and B), and the minimum cardinality on both sides is 1. That would mean before table A can be filled, table B needs a record that table A can be linked to. But…
user1534664
  • 3,258
  • 8
  • 40
  • 66
0
votes
0 answers

How to ensure referential integrity many not strictly hierarchical entities?

Say I have three entities(or tables): School, Student and Classroom. How do I ensure a Student belongs to a Classroom which belongs to the same School the Student belongs to? Considering a Student may not be part of any Classroom. I'm facing that…
caeus
  • 3,084
  • 1
  • 22
  • 36
0
votes
0 answers

SQL Server. Table resides in a filegroup which is not online

I have such a table structure: CREATE TABLE Table1 ( Id1 INT IDENTITY(1,1) NOT NULL PRIMARY KEY, Value VARCHAR(50) ) ON [PRIMARY] GO CREATE TABLE Table2 ( Id2 INT IDENTITY(1,1) NOT NULL PRIMARY KEY, Value VARCHAR(50) ) ON…
GriGrim
  • 2,891
  • 1
  • 19
  • 33
0
votes
4 answers

Referential integrity where multiple allocations in each table?

Ok so, I have a Projects Table and an Employees Table. First I keep getting very confused how I should set up the PK and FK in general. I have Customers table and I want it so 1 customer can have multiple Projects at a time. So the solution is to…
user3467440
0
votes
1 answer

Simplify Many-to-Many Relation with Extra Field

I would like to simplify a Many-to-Many Relation complex, composed by key with 4 fields, one of which is used to establish dependency (serie: is order of creation). I know that should break the table and keep dependencies, but after reading and…
0
votes
0 answers

Optimal join on not null, foreign key relationship

I have two tables, ONE and MANY. ONE.listId (int, not null, primary or unique) is related to MANY.listId (int, not null) via foreign key constraint with CASCADE on delete/update. When SELECTing over this relationship via: SELECT ONE.field AS…
Mark K Cowan
  • 1,755
  • 1
  • 20
  • 28
0
votes
1 answer

SQL Reference multiple tables

I want to define a mapping in SQL. The mapping is from one source table to several target tables. I'm using referential integrity, so if a value in the source table is deleted, the value in the mapping table should be deleted as well. The defination…
el smu
  • 35
  • 1
  • 2
  • 8
0
votes
1 answer

Can RI Constraint be applied on a Non-Primary Key column?

We have a situation where we need to have a RI constraint on a non-Primary key column of the table. Scenario: **TABLE_2** **Unique_Key Expression_Key Data** 132 ASDF123 qweqwr 458 PQRS789 abcd **TABLE_1** …
user3363495
  • 155
  • 2
  • 10
0
votes
3 answers

SQL Oracle Determining Primary Key Values

In Oracle SQL what is the best way to create primary key values for an entity? I have been adding 100 for each different entity and incrementing new entities by 1, but I can see how this is not good because if I have over 100 inserts into a table I…
Bhetzie
  • 2,852
  • 10
  • 32
  • 43
0
votes
1 answer

How to make referential integrity?

I have an Oracle database with three tables : Table1 : Vehicle ID Type Item Table2 : Car ID Brand Table3 : Bus ID Bus Number In table 1 : if the type of the vehicle is Car, I want the column Item to store an ID from Car table ; if the type of…
Thomas Carlton
  • 5,344
  • 10
  • 63
  • 126
0
votes
3 answers

Prevent insertion of additional child rows

My application involves using submitting data (the "request") from a form into an SQL Server 2005 database, for later review and approval by a supervisor. Users should have permission to insert a new request, but not be able to modify the ones they…
Todd Owen
  • 15,650
  • 7
  • 54
  • 52
0
votes
2 answers

mysql - referential integrity across multiple databases?

I have two databases in a php / mysql application. One for user data and the other for content. I have recently had to make use of inno db tables in order to enforce some referential integrity. Obviously, the user tables will be required to…
Dan
  • 4,068
  • 10
  • 41
  • 51
0
votes
1 answer

mysql foreign key not violated

I am using mysql. When I add a foreign key to a table it is done without any errors. When the table structure is described i see MUL under the key field like I see the the PRI for the columns set as the primary key. But when I try to violate the…
0
votes
3 answers

Integrity constraint error again

I am creating four database tables by the following schemas but am getting an integrity constraint violation error. Here is my entire schema along with the queries to populate the tables: create table Employee( Lastname varchar(10), …
user1462294
  • 167
  • 4
  • 13
0
votes
0 answers

Can't find integrity constraint violation

I am trying to get this SQL schema together for an Employee Database with four different tables (Employee information, Work information, company information, and manager information) and got the following error when attempting building the…
user1462294
  • 167
  • 4
  • 13