Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error Inserting Data into tables in SQL Server

I am getting errors when inserting these data into the table Course.

INSERT INTO Course (Course_ID,Course_Name)
VALUES ('2019','CS');
VALUES ('1033','science');
VALUES ('1055','history');
VALUES ('3001','French');

Here is the details for creation of the table Course:

CREATE TABLE 
(
  Course_ID INT NOT NULL,
  Course_Name VARCHAR(30) NOT NULL,
  PRIMARY KEY (Course_ID)
);
like image 725
Elfin forest Avatar asked Apr 07 '17 19:04

Elfin forest


1 Answers

You do not need to repeat values, you do need to use a comma between sets of values, and the semicolon to terminate the statement is optional (but good practice).

INSERT INTO Course (Course_ID,Course_Name) VALUES 
  ('2019','CS')
, ('1033','science')
, ('1055','history')
, ('3001','French');

Reference:

  • Table Value Constructor (Transact-SQL)

rextester demo: http://rextester.com/DBYKYI20580

like image 191
SqlZim Avatar answered Sep 28 '22 07:09

SqlZim