简体   繁体   中英

SQL Server: the identity column must be of data type int, bigint, smallint, tinyint, decimal, or numeric

I use SQL Server 2017 Management Studio, and I try to create encrypted columns (with always encrypted task) and I get an error

The identity column must be of data type int, bigint, smallint, tinyint, decimal, or numeric with a scale of 0, unencrypted, and constrained to be nonnullable.

My tables are:

create table testDB.dbo.Login
(
    ID INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
    Username varchar(20) NOT NULL UNIQUE,
    Password varchar(128) NOT NULL,
    Email varchar(100) Not Null UNIQUE
);

create table testDB.dbo.Admin
(
    ID INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
    Admin INT NOT NULL FOREIGN KEY REFERENCES testDB.dbo.Login(ID)
);

How can I solve this problem?

For format identity key Try this:

"padded_id" was the name I used in the computed column example.

create table table
(
   id int IDENTITY(1,1) NOT NULL,
   padded_id AS (right('0000000000' + CONVERT(varchar(10),id),10)) PERSISTED 
    NOT NULL,
   other columns....
)

尝试加密其他列离开标识列和外键引用列。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM