0

我有一个结构如下的表:

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用于二进制类型。我有什么选择?

4

2 回答 2

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
    );
于 2013-04-24T11:59:12.677 回答
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
于 2013-04-24T12:03:42.250 回答