create table staff(
staffnum int(10) not null,
staffname varchar(20) not null,
staffage varchar(20) not null,
stafftitle varchar(30) not null,
staffleader varchar(20) not null,
primary key(staffnum)
);表staff中怎样把staffleader设置为该表的外键?急啊。
这样写foreign key(staffleader) references staff(staffnum)会报错
staffnum int(10) not null,
staffname varchar(20) not null,
staffage varchar(20) not null,
stafftitle varchar(30) not null,
staffleader varchar(20) not null,
primary key(staffnum)
);表staff中怎样把staffleader设置为该表的外键?急啊。
这样写foreign key(staffleader) references staff(staffnum)会报错
解决方案 »
- 在C#中执行SQL特殊字段怎么处理?
- 这句话到底是什么意思
- 有个小问题,帮忙看下,在线等,谢!
- Mysql为root@%用户分配event权限,Access denied for user 'root'@'%' (using password:YES)
- 如何将A数据库内的表复制到B数据库?
- 请大家帮帮忙!!!
- 急:存储过程问题,各位高人帮忙看看错在哪了,不能得出正确结果,谢谢:) 分不够,再加!
- “[Microsoft][ODBC SQL Server Driver]超时已过期”的问题
- 如何在SQL SERVER中进行递归?
- SQL SERVER中如何取年、月、日。不难吧
- DTSRun命令问题,DTSRun /~Z0xFEF6B67A55B120...
- 我的这条sql语句错在哪里?
mysql> create table staff(
-> staffnum int(10) not null,
-> staffname varchar(20) not null,
-> staffage varchar(20) not null,
-> stafftitle varchar(30) not null,
-> staffleader varchar(20) not null,
-> storage_num int(10) not null,
-> primary key(staffnum),
-> foreign key(staffleader) references staff(staffnum),
-> foreign key(storage_num) references storage(storage_num)
-> )
-> engine=innodb;
ERROR 1005 (HY000): Can't create table 'facmanage.staff' (errno: 150)
staffnum int not null, --int 数据类型不能指定列宽
staffname varchar(20) not null,
staffage varchar(20) not null,
stafftitle varchar(30) not null,
staffleader int not null, --外键列数据类型必须与主键列相同
primary key(staffnum)
);
go
ALTER TABLE staff ADD CONSTRAINT
FK_staff_staff FOREIGN KEY
(
staffleader
) REFERENCES staff
(
staffnum
) ON UPDATE NO ACTION
ON DELETE NO ACTION
/*
命令已成功完成。
*/
GO
drop table staff
ON DELETE NO ACTION 是什么意思啊?