Home > SQL > t-sql: Default value of a column depending on another field

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
VN:F [1.9.18_1163]
Rating: 4.0/5 (2 votes cast)
t-sql: Default value of a column depending on another field, 4.0 out of 5 based on 2 ratings

No related posts.

Categories: SQL