sql – H2数据库CREATE TABLE与约束

前端之家收集整理的这篇文章主要介绍了sql – H2数据库CREATE TABLE与约束前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有两个sql语句:
CREATE TABLE legs(legid INT PRIMARY KEY AUTO_INCREMENT NOT NULL,playerid1 INT NOT NULL REFERENCES players(playerid),playerid2 INT NOT NULL REFERENCES players(playerid),added TIMESTAMP AS CURRENT_TIMESTAMP NOT NULL);

ALTER TABLE legs ADD CONSTRAINT distinct_players CHECK(playerid1 <> playerid2);

我99%肯定我能把它们凝聚成一个,即:

CREATE TABLE table(...
                   playerid2 INT NOT NULL REFERENCES players(playerid) CHECK(playerid1 <> playerid2),...);

但是,我一直在收到语法错误. AFAIK,这是约束应该在哪里.

解决方法

CREATE TABLE legs(legid INT PRIMARY KEY AUTO_INCREMENT NOT NULL,added TIMESTAMP AS CURRENT_TIMESTAMP NOT NULL,CHECK (playerid1 <> playerid2));

猜你在找的MsSQL相关文章