create database assessment3;
使用评估3;
创建表Employee ( eID int NOT NULL IDENTITY(1,1)主键, eName varchar(25)NOT NULL, Mgr int NULL, 作业文字NOT NULL, 工资int NOT NULL, 通信 hDate日期NOT NULL, dID int NOT NULL, );
插入Employee(eName,Mgr,Job,Salary,Comm,hDate,dID) 值('ken Adams',1004,'Salesman',70000,20000,'2008-04-12',1), ('Ru Jones',1004,'Salesman',65000,15000,'2010-01-18',1), ('Dhal Sim',1006,'Accountant',88000,NULL,'2001-03-07',2), ('Ellen Honda',1006,'Manager',118000,NULL,'2001-03-17',1), ('Mike Bal',1006,'Receptionist',68000,NULL,'2006-06-21',3), ('Martin Bison',NULL,'CEO',210000,NULL,'2010-07-12',3), ('神力',1004,'推销员',86000,18000,'2014-09-18',1), ('Zang Ross',1004,'Salesman',65000,10000,'2017-02-02',1), ('Sagar Kahn',1004,'Salesman',70000,15000,'2016-03-01',1);
从员工中选择*;
从Employee中选择eID,eName,工作,其中Job ='Salesman'和hDate> '01 -01-2014';
我已经创建了数据库,但是在插入数据库信息时 我的输出显示错误
消息402,第16级,状态1,第30行 文本类型和varchar数据类型在等于运算符中不兼容。
(受影响的0行)
我该如何解决这个问题并使表格显示在结果中。另外,我使用SQL Management Studio 2017
答案 0 :(得分:0)
由于MGR
不是nullable
列,但是您正在将null值插入到列中,因此失败
尝试这样
create table #Employee
(
eID int NOT NULL IDENTITY(1,1) PRIMARY KEY,
eName varchar(25) NOT NULL,
Mgr int NOT NULL,
Job text NOT NULL,
Salary int NOT NULL,
Comm int,
hDate date NOT NULL,
dID int NOT NULL,
);
alter table #Employee
alter column Mgr int null
insert into #Employee(eName, Mgr, Job, Salary, Comm, hDate, dID)
values ('ken Adams', 1004, 'Salesman', 70000, 20000, '2008-04-12', 1),
('Ru Jones', 1004, 'Salesman', 65000, 15000, '2010-01-18', 1),
('Dhal Sim', 1006, 'Accountant', 88000, NULL, '2001-03-07', 2),
('Ellen Honda', 1006, 'Manager', 118000, NULL, '2001-03-17', 1),
('Mike Bal', 1006, 'Receptionist', 68000, NULL, '2006-06-21', 3),
('Martin Bison', NULL, 'CEO', 210000, NULL, '2010-07-12', 3),
('Shen Li', 1004, 'Salesman', 86000, 18000, '2014-09-18', 1),
('Zang Ross', 1004, 'Salesman', 65000, 10000, '2017-02-02', 1),
('Sagar Kahn', 1004, 'Salesman', 70000, 15000, '2016-03-01', 1);