Fares
Fares

Reputation: 364

Column Constraint Sql 2008

I have been trying to find out if I can make a column Open on Insert, and closed on Update. What I mean by that, is I need a column that I can give it a value only on Insert, but if I try to give it a value with Update, the statement would fail.

I am working with SQL 2008...

Upvotes: 0

Views: 53

Answers (1)

Oded
Oded

Reputation: 498914

You can't do this with constraints - you need to use triggers for this.

A trigger is a special kind of stored procedure that automatically executes when an event occurs in the database server. DML triggers execute when a user tries to modify data through a data manipulation language (DML) event. DML events are INSERT, UPDATE, or DELETE statements on a table or view.

Upvotes: 1

Related Questions