create table tb_customerinfo ( CustomerId int identity, CustomerName varchar(20) not null, CustomerPwd varchar(20) not null, Customertruename varchar(20) not null, CustomerSex varchar(2) not null constraint CKC_CUSTOMERSEX_TB_CUSTO check (CustomerSex in ('男','女')), CustomerTel varchar(20) not null, CustomerEmail varchar(20) not null, CustomerAddr varchar(20) not null, CustomerRegTime datetime not null, CustomerQues varchar(200) null, CustomerAnswer varchar(200) null, CustomerLogTime int not null, CustomerLastLogT datetime not null, constraint PK_TB_CUSTOMERINFO primary key(CustomerId, CustomerName) ) 以上代码在identity,如何修改
时间: 2024-02-07 22:02:27 浏览: 221
CustomerInfo.zip
如果您希望修改上述代码,可以考虑使用自增序列而不是IDENTITY,如下所示:
```
create sequence seq_customerinfo as int start with 1 increment by 1;
create table tb_customerinfo (
CustomerId int default (next value for seq_customerinfo),
CustomerName varchar(20) not null,
CustomerPwd varchar(20) not null,
Customertruename varchar(20) not null,
CustomerSex varchar(2) not null constraint CKC_CUSTOMERSEX_TB_CUSTO check (CustomerSex in ('男','女')),
CustomerTel varchar(20) not null,
CustomerEmail varchar(20) not null,
CustomerAddr varchar(20) not null,
CustomerRegTime datetime not null,
CustomerQues varchar(200) null,
CustomerAnswer varchar(200) null,
CustomerLogTime int not null,
CustomerLastLogT datetime not null,
constraint PK_TB_CUSTOMERINFO primary key(CustomerId, CustomerName)
);
```
这样就可以使用自增序列seq_customerinfo来生成CustomerId,而不使用IDENTITY。
阅读全文