Does a View ignore Constraints?

  • My customer needs to assign contract numbers to salespersons and vendors in advance. What I want to do is create a view with just the ContractID, Salesperson and VendorID fields validated. Later, when they edit the contract directly, I want all of the Constraints to fire.

    Will that work? Will a view of just those three fields allow me to enter a record that has as NULL fields that in the Table view are not allowed to be NULL?

    "What I lack in youth I make up for in immaturity!"
    Please visit my music site at http://woundedego.com

  • No, sorry. Don't think of a View as a separate storage for records, think of it as just an alias for a table expression.

    I think that you might want more complex constraints than you currently have. You may want to look into using triggers to make these constraints more sophisticated.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • Ok, thanks. Then is there a way to know inside of my Trigger whence the trigger is being called - whether from the view or from the table?

    "What I lack in youth I make up for in immaturity!"
    Please visit my music site at http://woundedego.com

  • Presumably, you would have to figure it out from context and the data state of the record. Maybe keep a STATE or STATUS column that indicated where in your process the record was and applied different restrictions based on that.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • That makes sense. Thanks.

    "What I lack in youth I make up for in immaturity!"
    Please visit my music site at http://woundedego.com

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply