Answer the question
In order to leave comments, you need to log in
How to ensure the integrity of a ms sql server database?
For example, let's take 2 simple tables with Products (Products) and Suppliers (Vendors).
It is necessary that it is not allowed to delete the Supplier (Vendor) if there is an entry in Products with its id.
I know that this can be done with a diagram. (we put the primary key on the Supplier and the foreign key on the Product).
Based on the definition of diagrams:
Charts are database components that block the deletion of records from primary tables if there are records associated with them in secondary tables. Therefore, charts prevent data integrity violations. In SQL Server, charts are created using the Chart Wizard
Answer the question
In order to leave comments, you need to log in
Use a foreign key , it is specifically designed for this:
ALTER TABLE Products ADD FOREIGN KEY(vendorId) REFERENCES Vendors(id);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question