Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Referential Integrity Question [modified]

Referential Integrity Question [modified]

Scheduled Pinned Locked Moved Database
databasehelptutorialsql-serversysadmin
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xfitr2
    wrote on last edited by
    #1

    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.

    T 1 Reply Last reply
    0
    • X xfitr2

      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.

      T Offline
      T Offline
      ToddHileHoffer
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups