Adding Checks after a table is created in SQL Server

Did you create a table, only to find that you need to add a check constraint? I created a quick example of how to add a check constraint after the table exists. In this example, we want to know if our user is alive or dead. 1 = alive, 0 = dead. Here is the code for SQL server:

alter table dbo.Tbl_User_Table add constraint
CK_User_Alive check (User_Alive in (0,1))

I don’t know if it will work with MySql, Oracle, etc, so check your documentation. Happy Coding!

Rudy

Rudy Rodarte is a SQL Server Database professional based in Austin, TX. Over his career, Rudy has worked with SSRS, SSIS, performance tuning troubleshooting. When away from Keyboard, Rudy goes to Spurs and Baylor Bear sporting events.

More Posts - Website - Twitter