Skip to content
Advertisement

How do I get constraints on a SQL Server table column

I have a column called MealType (VARCHAR) in my table with a CHECK constraint for {"Veg", "NonVeg", "Vegan"}

That’ll take care of insertion.

I’d like to display these options for selection, but I couldn’t figure out the SQL query to find out the constraints of a particular column in a table.

From a first glance at system tables in SQL Server, it seems like I’ll need to use SQL Server’s API to get the info. I was hoping for a SQL query itself to get it.

Advertisement

Answer

This query should show you all the constraints on a table:

can replace the select statement with this:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement