IF EXISTS ( SELECT [name] FROM sys.databases WHERE [name] = 'BlogDB' )
DROP DATABASE BlogDB
GO
CREATE DATABASE BlogDB
GO
IF EXISTS ( SELECT [name] FROM sys.tables WHERE [name] = 'Editor' )
DROP TABLE Editor
GO
CREATE TABLE Editor
(
UsernameID VARCHAR (30),
EMail VARCHAR (30),
DateOfBirth VARCHAR(30),
BlogTitle VARCHAR(30),
PRIMARY KEY(UsernameID)
);
INSERT INTO Editor VALUES ('Mdbuzzer', 'coker@hotmail.com', '1995/03/15', 'Nearly Bound');
INSERT INTO Editor VALUES ('Kally32', 'kally@hotmail.com', '1993/10/13', 'Tomorrows War');
SELECT * FROM Editor;
IF EXISTS ( SELECT [name] FROM sys.tables WHERE [name] = 'Post' )
DROP TABLE Post
GO
CREATE TABLE Post
(
UsernameID VARCHAR(30),
BlogTitle VARCHAR (30),
PostTitle VARCHAR (30),
Category VARCHAR (20),
TimeofPost VARCHAR (10)
);
INSERT INTO Post VALUES ('Kally32','Tomorrows War', 'Mystery', 'General', '12:03pm');
INSERT INTO Post VALUES ('Kally32','Tomorrows War', 'Let It Shine','Musing','10:05pm');
INSERT INTO Post VALUES ('Kally32', 'Tomorrows War','Two Can Play That Game','Work', '12:00pm');
INSERT INTO Post VALUES ('Mdbuzzer','Nearly Bound', 'Goal','Social', '10:05pm');
INSERT INTO Post VALUES ('Mdbuzzer', 'Nearly Bound','Life After Death','General', '12:03pm');
INSERT INTO Post VALUES ('Mdbuzzer', 'Nearly Bound','Times Up','Work', '14:06');
SELECT * FROM Post;
IF EXISTS ( SELECT [name] FROM sys.tables WHERE [name] = 'Comments' )
DROP TABLE Comments
GO
CREATE TABLE Comments
(
UsernameID VARCHAR (30),
PostTitle VARCHAR (50),
Comments VARCHAR (100),
TimeofComments VARCHAR (10)
);
INSERT INTO Comments VALUES ('Kally32','Mystery', 'Highly Recommend', '18:36pm');
INSERT INTO Comments VALUES ('Kally32','Let It Shine', 'Touching story', '19:46pm');
INSERT INTO Comments VALUES ('Kally32','Two Can Play That Game', 'Truly Remarkable', '13:40pm');
INSERT INTO Comments VALUES ('Kally32','Let It Shine', 'Amazing Ending', '09:36am');
INSERT INTO Comments VALUES ('Kally32','Mystery', 'Highly Recommend', '20:36pm');
INSERT INTO Comments VALUES ('Mdbuzzer','Goal', 'I love the team spirit at the end', '18:36pm');
INSERT INTO Comments VALUES ('Mdbuzzer','Life After Death','Very Emotional', '08:40am');
INSERT INTO Comments VALUES ('Mdbuzzer','Times Up', 'Brings back memories', '23:16pm');
INSERT INTO Comments VALUES ('Mdbuzzer','Times Up', 'Best post I have seen in a while', '22:55pm', '22:00pm');
INSERT INTO Comments VALUES ('Mdbuzzer','Life After Death', 'A touching story', '09:50am', '07:00am');
SELECT * FROM Comments;
我在尝试执行脚本时遇到错误我不确定问题是什么,如果有人能帮助我,我将不胜感激。它说错误在
16级,州1,第25行
答案 0 :(得分:2)
下面:
INSERT INTO Comments VALUES
('Mdbuzzer','Times Up', 'Best post I have seen in a while', '22:55pm', '22:00pm');
您正在将5个值插入到包含4列的表中。
有时使用更详细的语法可以帮助组织和错误消息:
INSERT INTO Comments(UsernameID, PostTitle, Comments, TimeofComments)
VALUES('Mdbuzzer','Times Up', 'Best post I have seen in a while', '22:55pm', '22:00pm');