CREATE TABLE Usuario
(
id int identity not null,
usuario char(20) unique not null,
senha char(10) not null,
tipo_usuario char(15) not null,
primary key (id),
foreign key (tipo_usuario) references TpoUsuario
on update cascade on delete set default
);
CREATE TABLE TpoUsuario
(
id int identity not null,
tipo_usuario char(15) not null,
primary key(id)
);
这使用代码顶部,并收到此消息错误。错误创建外键SQL
首先我创建了表TpoUsuario
,然后我创建了表Usuario
。
消息1778年,级别16,状态0,第1行
列 'TpoUsuario.id' 是不相同的数据类型为外键 'FK__Usuario__tipo_us__60A75C0F' 的引用列 'Usuario.tipo_usuario'。Msg 1750,Level 16,State 0,Line 1
无法创建约束。查看以前的错误。
您正在使用哪些DBMS?阅读错误消息。数据类型不匹配 - 你试图在TpoUsuario.id上创建一个外键(我想你不想使用它们的列)和Usuario.tipo_usuario。 – MrTux 2014-08-27 16:37:38
我使用SQL Server管理工作室 – 2014-08-27 16:55:19
SSMS是你的客户端工具,你的DBMS将是类似于SQL Server 2008 R2,Oracle 11,MySQL等。 – AHiggins 2014-08-27 17:01:16