如何使用Check Constraint - SQL Server进行alter table

时间:2018-04-18 06:09:47

标签: sql-server tsql alter-table check-constraints

CREATE TABLE publishers
(
    PublisherName    varchar(75),
    City                    varchar(35),
    PublisherState    char(2),
    Country            varchar(4)
)
GO 

- 修改发布商,以便州必须是两个字母

ALTER TABLE publishers
    ALTER COLUMN publisherstate char(2) CHECK (publisherstate LIKE '[A-Za-z][A-Za-z]')​

1 个答案:

答案 0 :(得分:1)

您必须提及Constraint NameCheck

试试这个:

alter table publishers
add constraint codeCheck check (PublisherState like '[A-Za-z][A-Za-z]');