t-sql: Default value of a column depending on another field
Below INSERT TRIGGER code updates the value of SortOrder column with the maximum value in that column + 1
CREATE TRIGGER trigger_UpdateSortOrder ON arc_Categories FOR INSERT AS UPDATE arc_Categories SET sortorder = (SELECT MAX(sortorder)+1 FROM arc_Categories) WHERE CatID = @@IDENTITY GO
No related posts.
Categories: SQL
Recent Comments