新人的问题
create table dept(
deptno int primary key,
dname nvarchar(20),
loc nvarchar(20)
)
insert into dept values(10, 'ACCOUNTING', 'NEW YORK')
insert into dept values(20, 'RESEARCH', 'DALLAS')
insert into dept values(30, 'SALES', 'CHICAGO')
insert into dept values(40, 'OPERATIONS', 'BOSTON')
insert into dept values(50, 'ADVERTISEMENT', 'BEIJING')
create table emp
(
EMPNO int primary key,
ename nvarchar(50),
job nvarchar(20),
constraint mgr foreign key(EMPNO)references emp(EMPNO),
hiredate date,
sal int,
comm int,
constraint deptno foreign key(deptno) references dept(deptno)
)
insert into emp values(7369, 'SMITH', 'CLERK', 7902, 1987-12-17, 800, NULL, 20)
insert into emp values(7499, 'ALLEN', 'SALESMAN', 7698, 1981-2-20, 1600, 300, 30)
insert into emp values(7521, 'WARD', 'SALESMAN', 7698, 1981-2-22, 1250, 500, 30)
insert into emp values(7566, 'JONES', 'MANAGER', 7839, 1987-4-2, 2975, NULL, 20)
insert into emp values(7654, 'MARTIN', 'SALESMAN', 7698, 1987-9-28, 1250, 1400, 30)
insert into emp values(7698, 'BLAKE', 'MANAGER', 7839, 1981-5-1, 2850, NULL, 30)
insert into emp values(7782, 'CLARK', 'MANAGER', 7839, 1981-6-9, 2450, NULL, 10)
insert into emp values(7788, 'SCOTT', 'ANALYST', 7566, 1981-4-19, 3000, NULL, 20)
insert into emp values(7939, 'KING', 'PERSIDENT', NULL, 1981-11-17, 5000, NULL, 10)
insert into emp values(7844, 'TURNER', 'SALESMAN', 7698, 1981-9-8, 1500, 0, 30)
insert into emp values(7976, 'ADAMS', 'CLERK', 7788, 1987-5-23, 1100, NULL, 20)
insert into emp values(7900, 'JAMES', 'CLERK', 7698, 1981-12-3, 950, NULL, 30)
insert into emp values(7902, 'FORD', 'ANALYST', 7566, 1982-12-3, 3000, NULL, 20)
insert into emp values(7934, 'MILLER', 'CLERK', 7782, 1982-1-23, 1300, NULL, 10)
为什么 执行的时候
Msg 1769, Level 16, State 1, Line 15
外键 'deptno' 引用了位于引用表 'emp' 中的无效列 'deptno'。
Msg 1750, Level 16, State 0, Line 15
无法创建约束。请参阅前面的错误消息。
还有请问 日期的代码要怎么打。
[ 本帖最后由 allenz0810 于 2012-9-20 10:53 编辑 ]