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

Proper foreign keys for MS SQL Server 2005 without UNIQUE constraints?

I have two tables (MS SQL Server 2005) with an existing application (no DB alterations other than indexes, etc are allowed). The two tables are: ActivityDetails (Primary table) ActivityDetailkey (Primary key) SubActivities (Child table) …
cbmeeks
  • 11,248
  • 22
  • 85
  • 136
1
vote
3 answers

Should I enforce business logic through database errors?

There's an interesting design decision I've been thinking about lately. Let's say I'm adding usernames to a table, and I want to make sure there are no duplicates. The username column is NOT NULL UNIQUE. I could either: Query the database before…
zildjohn01
  • 11,339
  • 6
  • 52
  • 58
1
vote
2 answers

How to check Foreign Key to restrict SoftDelete?

I would like to know if it is possible to check FK when using SoftDelete with ASP.NET Boilerplate. Example Suppose these tables: Roles: RoleId (PK) - Description Users: UserId (PK) - Name - RoleId (FK with Roles) Data: Roles 1 - admin 2 -…
1
vote
3 answers

Whats the best way to populate two tables with records that need to reference each other?

What is the best way to populate records in two tables that each need a reference to the primary key of the other? My thoughts are either having a "link" table between them which is populated once both have been written to the db or by the following…
Omar Kooheji
  • 54,530
  • 68
  • 182
  • 238
1
vote
2 answers

when delete document in another collection How to delete edge collection document together?

I am practicing arangodb in company. When I want to express the following relation between the user and the user, I want to delete the data of the corresponding following relation when one user is deleted. user collection { "_key": "test4", …
park
  • 11
  • 3
1
vote
2 answers

split table rows of data into multiple tables according to column obeying constraints

I have a source flat file with about 20 columns of data an roughly 11K records. Each record (row) contains info such as…
1
vote
1 answer

Constraint stops DELETE in my own procedure, yet same DELETE runs in SQLPlus

On running two DELETE statements inside my own Package.Procedure: DELETE FROM ENT_PLANT_RELATIVE WHERE CHILD_ID = plant_id; DELETE FROM ENT_PLANT_ITEM WHERE PLANT_ID = plant_id; ... I receive an integrity constraint violation on the second DELETE…
1
vote
1 answer

Not able to assign On Delete Set null and on updated set Null in mysql

bank_api_uat_user Table CREATE TABLE IF NOT EXISTS `bank_api_uat_user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `bank_name` varchar(255) DEFAULT NULL, `role` varchar(10) NOT NULL, `bank_code` char(10) NOT NULL, `user_name` varchar(255) NOT…
Jasshh Andrews
  • 175
  • 1
  • 15
1
vote
1 answer

MS Access Data-Definition Query Add Referential Integrity Constraint

I am trying to write a data-definition query to add a constraint to a table that enforces referential integrity ALTER TABLE SS_SIZE ALTER COLUMN NDS TEXT CONSTRAINT fk_NDS REFERENCES NDS (NDS) ON UPDATE CASCADE ON DELETE CASCADE I've also…
1
vote
1 answer

Integrity constraint violated - parent key not found when calling stored procedure

I'm trying to perform the stored package procedure call in Oracle 11g XE, but for some reason I get the error below: Error report - ORA-02291: integrity constraint (ROOT.SYS_C007057) violated - parent key not found ORA-06512: at…
1
vote
3 answers

How can Hard Deletes work when Foreign Keys are involved

I need some wisdom shed on the controversy over soft-deletes vs hard-deletes in a relational-database-centric application. Commentaries like this, this, and this all discourage soft-deletes as basically a hack, a dirty, easy way out, and claim that…
BCA
  • 7,776
  • 3
  • 38
  • 53
1
vote
3 answers

Checking that an object exists in DB (Django)

Consider this Django code: class User(models.Model): name = models.CharField(null=True, blank=False, verbose_name=_("Name"), help_text='User Name', max_length=256) class UsersGroup(models.Model): name = models.CharField(null=False,…
porton
  • 5,214
  • 11
  • 47
  • 95
1
vote
3 answers

Should my RDBMS or my Application handle database Referential Integrity?

Should items like Foreign Keys, Constraints, Default Values, etc be handled by the Database management system (in this case, MS Sql 2005) or the Application? I have heard opinions from both sides and I'm honestly not sure which way to go. I…
Rachel
  • 130,264
  • 66
  • 304
  • 490
1
vote
1 answer

Delete a MySQL record involved in a foreign key without deleting children

i am trying to delete a row of information from a parent table without deleting anything from the child table. the foreign key constraint is set to delete no action. because i want to delete the information while leaving the corresponding…
1
vote
7 answers

Factoring out nulls in bill-of-materials style relations

Given the schema PERSON { name, spouse } where PERSON.spouse is a foreign key to PERSON.name, NULLs will be necessary when a person is unmarried or we don't have any info. Going with the argument against nulls, how do you avoid them in this…
Dave
  • 4,546
  • 2
  • 38
  • 59