代码:
create table student
(
s_id int not null primary key identity(1,1),
s_fname varchar(30) not null,
s_lname varchar(50) not null,
s_branch varchar(4) not null,
pointer float(50) ,
s_dob date not null
);
drop table student;
select *
from student;
insert into student (s_fname, s_lname, s_branch, pointer, s_dob)
values (('abc', 'xyz', 'CMPN', 8.5, '1996-03-14'),
('lmn', 'pqr', 'EXTC', 7, '1997-03-23')
);
我无法纠正错误是什么。
我得到的错误消息是
Msg 102,Level 15,State 1,Line 15
附近的语法不正确
','
答案 0 :(得分:3)
您需要删除()
子句中的最外层VALUES
:
create table student
(
s_id int not null primary key identity(1,1),
s_fname varchar(30) not null,
s_lname varchar(50) not null,
s_branch varchar(4) not null,
pointer float(50) ,
s_dob date not null
);
insert into student (s_fname,s_lname,s_branch,pointer,s_dob)
values
('abc','xyz','CMPN',8.5,'1996-03-14'),
('lmn','pqr','EXTC',7,'1997-03-23');
select * from student;
的 LiveDemo
强>
drop table student;
也应该删除/评论。
答案 1 :(得分:0)
根据我上面的评论,我认为你的代码应该是这样的:
create table student
(
s_id int not null primary key identity(1,1),
s_fname varchar(30) not null,
s_lname varchar(50) not null,
s_branch varchar(4) not null,
pointer float(50) ,
s_dob date not null
);
--drop table student;
insert into student (s_fname,s_lname,s_branch,pointer,s_dob)
values ('abc','xyz','CMPN',8.5,'1996-03-14'),
('lmn','pqr','EXTC',7,'1997-03-23');
select * from student;
答案 2 :(得分:0)
所以我相信你有一个drop table语句来确保在开始创建表之前表不应该存在。
执行此操作的正确方法如下所示,我们只删除现有的student
表,然后创建它,填充它然后在其上运行select *
if object_id('dbo.student', 'u') is not null
drop table dbo.student;
create table student
(
s_id int not null primary key identity(1,1),
s_fname varchar(30) not null,
s_lname varchar(50) not null,
s_branch varchar(4) not null,
pointer float(50) ,
s_dob date not null
);
insert into student (s_fname,s_lname,s_branch,pointer,s_dob)
values
('abc','xyz','CMPN',8.5,'1996-03-14'),
('lmn','pqr','EXTC',7,'1997-03-23');
select * from student;