What is referential integrity in SQL Server ?

 Posted by Bhakti on 11/15/2009 | Category: Sql Server Interview questions | Views: 11876

To avoid logically corruption of data we need to maintain relationships with most of the databases. Building and maintaining logical relationships between tables is essential part to work with relational databases and when such relationships exist, we say that the data has referential integrity. With such database one table is referenced table and the other is the referencing table and values with both the tables (referencing table and referenced table) must match.
We can enforce such referential integrity through foreign key constraints.

For an example,…
CREATE TABLE Table_Referenced 

id INT
CONSTRAINT pk_id PRIMARY KEY(id)--Create Primary Key here

CREATE TABLE Table_Referencing
CONSTRAINT fk_RID FOREIGN KEY(RID)REFERENCES Table_Referenced(id)--Creates foreign key names 'RID' which is referring primary key of Table_Referenced.id

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response