Hi, I have got a simple question about below two tables relationship. Does the two tables ensure that every corresponding Update and delete on Customers table updates and deletes the credit card details as well??? your replies are much appreciated. Cheers!!!! **** Credit CardDetails Table ****** USE DWDatabase GO IF EXISTS(SELECT name FROM sys.tables WHERE name='CreditCardDetails') DROP TABLE CreditCardDetails GO CREATE TABLE CreditCardDetails ( CreditCardID INT NOT NULL PRIMARY KEY IDENTITY(1,1), CardNumber NVARCHAR(50) NOT NULL, CardHoldersName NVARCHAR(50) NOT NULL, CardStartDate DATETIME NOT NULL, CardEndDate DATETIME NOT NULL, Securitycode INT NOT NULL, CustomerID INT References Customer(CustomerID) ON DELETE CASCADE ON UPDATE CASCADE, ) USE DWDatabase GO IF EXISTS( SELECT name FROM sys.tables WHERE name='Customer')DROP TABLE Customer GO **** Customer Table******* CREATE TABLE Customer ( CustomerID int NOT NULL PRIMARY KEY IDENTITY(1,1), CompanyName nvarchar(50), ContactFirstName nvarchar(50) NOT NULL, ContactSecondName nvarchar(50), BilingAddress nvarchar(50), City nvarchar(50), StateOrProvince nvarchar(30), PostalCode nvarchar(10), Country nvarchar(50), Title nvarchar(10), PhoneNumber nvarchar(50), FaxNumber nvarchar(50) )
If a customer changes the card details, I would like that to be updated on the carddetails table as well? How could I do that? If a customer changes the credit card details, the changes/updates reside in the CreditCardDetails table itself. I didn't get your question. And also I have got a Payments table, I want this table to pick up the carddetails automatically for the customer who made that order? Have I designed the tables right way? What exactly do you mean by Payments table being able to pick up the carddetails automatically? According to your table design, the foreign key enables you to pick the carddetails,payment details for the order using a proper query with proper joins. You don't have to give ON DELETE CASCADE or ON UPDATE CASCADE to foreign key. Basically, this is given on the primary key to say that if the record (in primary key table) is deleted or updated, reflect the changes in all the tables where the primary key table is referenced via foriegn key. |