Referential Integrity Question [modified]
-
DB: SQL Server 2005 I am trying to figure out how to check that a value exist before inserting/updating a record in a new table. Simplified Example below: Product Product_ID (int) Product_Name (varchar(25)) Inventory Inventory_ID (varchar(50)) Inventory_Product_ID (int) Inventory_PO_Item_ID (int) Inventory_Status (tinyint) I need to make sure that the Inventory.Inventory_Product_ID exists in the Product.Product_ID table before the record in the Inventory table is inserted/updated. I could create a stored procedure to do this, but the problem still exist that a record could accidentally be manually added to the table without cheking first. (Plus, I would like to throw an error in the stored procedure if the Inventory_Product_ID does not exist in the Products table.) I read that you can not use Select statements in contraints or rules. Would this be an example of using a trigger. If so, I am not too familiar with triggers and would appreciate some guidance with this problem. Thank you in advance.
-
DB: SQL Server 2005 I am trying to figure out how to check that a value exist before inserting/updating a record in a new table. Simplified Example below: Product Product_ID (int) Product_Name (varchar(25)) Inventory Inventory_ID (varchar(50)) Inventory_Product_ID (int) Inventory_PO_Item_ID (int) Inventory_Status (tinyint) I need to make sure that the Inventory.Inventory_Product_ID exists in the Product.Product_ID table before the record in the Inventory table is inserted/updated. I could create a stored procedure to do this, but the problem still exist that a record could accidentally be manually added to the table without cheking first. (Plus, I would like to throw an error in the stored procedure if the Inventory_Product_ID does not exist in the Products table.) I read that you can not use Select statements in contraints or rules. Would this be an example of using a trigger. If so, I am not too familiar with triggers and would appreciate some guidance with this problem. Thank you in advance.
Why not use a foreign key on Inventory_Product_ID to Product_ID?
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06