Click here to Skip to main content
14,298,693 members
Rate this:
Please Sign up or sign in to vote.
See more:
code =

insert into employee values
3,'dim',15000, 23, 'female','research'
4, 'tom',20000, 24, 'male','tech'

error =

Msg 102, Level 15, State 1, Line 6
Incorrect syntax near '4'.

What I have tried:

If add 3 and 4 separately they gets added.
Updated 8-Sep-19 20:06pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Semicolon in SQL terminates the statement: the system is expecting a new INSERT, SELECT, UPDATE, or similar command instead of more data.
Try this:
(3, 'dim', 15000, 23, 'female', 'research')
(4, 'tom', 20000, 24, 'male', 'tech');
But it's a very,. very good idea to list the column names on an INSERT operation:
INSERT INTO employee (ID, EmpName, Salary, Age, Sex, Dept)
(3, 'dim', 15000, 23, 'female', 'research')
(4, 'tom', 20000, 24, 'male', 'tech');
If you don't, then SQL will insert on a "current order" basis and that can cause problems if you change the table later. Naming the columns means you are saying exactly where each value should go, and that means it still works.

Couple of other style points:
1) Use plurals for table names: "Employees" rather than "Employee" - the later implies there is only one row and that can cause confusion with a column name later.
2) Use UPPER CASE for SQL keywords - it makes it more obvious what you intended - that way when you use a keyword as a column name the syntax highlighter makes it obvious you need to enclose it in square brackets.
3) Don't repeat information: "male" and "female" will occur a lot, as will department names. Use a separate table - "Genders" and "Departments" - and link to them via ID values. That way, your data is less prone to errors with "mlae" and "reseerch" being entered instead of the correct values.
sushanth bollaboina 9-Sep-19 2:42am
Thanks a lot sir !!

Iam new to SQL.
OriginalGriff 9-Sep-19 2:47am
You're welcome!
We all have to start somewhere!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100