日期:2014-05-18  浏览次数:20399 次

在线等 联合主键问题
SQL code

alter table NB_Consumer_2 add constraint UK_UserNameCrDate unique(UserID,CONVERT(varchar(10),CreDate,112))



这段代码 想把NB_Consumer_2 表里的 UserID 和 CreDate 做联合主键,如果Credate不做转换会有时分秒的问题,
就不是YYMMDD了
在不添加辅助字段的情况下,有啥方法能实现联合主键吧?

------解决方案--------------------
首先要把关系的字段改为非null的字段,再加上主健

给个例子你

SQL code

use tempdb
go

Create table Test(
ID int not null,
ID2 int not null--非null
)
go
alter table Test add constraint PK_Test primary key (ID,ID2)

------解决方案--------------------



你需要存时分秒吗? date类型如何?
要不就再加一个字段吧。