Database Reference
In-Depth Information
Figure 8-3. Showing the parent-child relationship between the Person and PersonDetails tables
Try It: Coding a Transaction in T-SQL
Follow these steps to code a transaction:
1. Here, you'll code a transaction based on the Person and PersonDetails tables,
where we will make use of SQL Server's primary key and foreign key rules to
understand how transactions work. The Person table has three columns. Two
columns, PersonID and FirstName, don't allow null values, and PersonID is
also a primary key column; that is, only unique values are allowed. Also, the
last column, Company, allows null values.
Similarly, the PersonDetails table is a foreign key or child table; it has a
PersonID column, which is a foreign key column and reference to
Person.PersonID. It also has an Address column. The child or foreign key table
can have only those records that have a matching primary key column value
available in the parent or primary key table, as shown in Figure 8-3. If a child
record that is inserted doesn't have a matching parent or primary key value,
then it will result in an error and not be inserted into the child table.
 
Search WWH ::




Custom Search