简体   繁体   中英

SQL Server : allow 3 letters and 4 numbers in a varchar(7) column

I'm trying to create a constraint for a SQL Server table in order to allow only 3 letters and 4 numbers on a single varchar(7) column.

Example: ABC1234

Can anyone help?

You could use:

ALTER TABLE tab_name ADD CONSTRAINT
constraint_name CHECK (col LIKE '[A-Z][A-Z][A-Z][0-9][0-9][0-9][0-9]');

Rextester Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM