Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server - How to change table column only having some specific values?

Tags:

sql-server

TABLE Family(
BrothersName varchar(30)
);

I have added some names (values) into BrothersName, but now I want it to only have 2 specific names 'Alex' and 'Tom'. However later it should also accept other names. What is the best way to handle this problem?

like image 212
Tomb_Raider_Legend Avatar asked Mar 28 '26 22:03

Tomb_Raider_Legend


1 Answers

Add a check constraint stating BrothersName should accept only 'Alex' and 'Tom'. In future when you don't need it you can drop the constraint

ALTER TABLE Family
ADD CONSTRAINT chk_BrothersName CHECK (BrothersName in ('Alex','Tom'))

To Drop the Check Constraint

ALTER TABLE Family
DROP CONSTRAINT chk_BrothersName
like image 144
Pரதீப் Avatar answered Mar 31 '26 03:03

Pரதீப்



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!