我的表格结构如下:
CREATE TABLE tb_comm_hist_xfer (
tb_comm_hist_xfer_id binary(16) NOT NULL,
tb_old_customer_id int NOT NULL,
tb_customer_id int NULL,
date_entered datetime NOT NULL
);
我想将tb_com_hist_xfer_id
列设为自动填充列,例如IDENTITY
属性。但我不能将IDENTITY
用于二进制类型。对我来说有什么选择?
答案 0 :(得分:3)
试试这个:
CREATE TABLE tb_comm_hist_xfer (
tb_comm_hist_xfer_id binary(50) default CONVERT(varbinary(50),NEWID()) NOT NULL,
tb_old_customer_id int NOT NULL,
tb_customer_id int NULL,
date_entered datetime NOT NULL
);
答案 1 :(得分:1)
您确定不想使用uniqueidentifier
吗?
CREATE TABLE tb_comm_hist_xfer (
tb_comm_hist_xfer_id uniqueidentifier default newid() NOT NULL,
tb_old_customer_id int NOT NULL,
tb_customer_id int NULL,
date_entered datetime NOT NULL
);
GO
insert into tb_comm_hist_xfer (tb_old_customer_id, tb_customer_id, date_entered) values (1, 2, getdate())
select cast(tb_comm_hist_xfer_id as binary(16)), * from tb_comm_hist_xfer