1

I have been using SQL for a bit now but have only recently tried out Microsoft SQL server Express. I have created a database called test and a table called idk. then I have tried to run the following query

USE test;
INSERT INTO idk(Id, Name) VALUES ("1","Name")

But that just says

Msg 207, Level 16, State 1, Line 2 Invalid column name '1'. Msg 207, Level 16, State 1, Line 2 Invalid column name 'Name'.

Any help for using SQL with Microsoft SQL server will be appreciated.

1
  • Welcome to the world of standard SQL.
    – mustaccio
    May 20, 2017 at 15:14

2 Answers 2

3

Use single quotes (') instead of double quotes (") for your values, such as:

USE test;
INSERT INTO idk(Id, Name) VALUES ('1','Name');

Using double quotes is one way to let SQL Server know you are specifying a column name instead of a value. Be careful about the data type for the ID. If it is an integer, SQL Server will convert the value in the query from a string to integer for you but it will be better to not have it as a string unless the data type is a string. For the ID, if it's an integer data type (int, bigint, smallint, or tinyint), then change the query as follows to remove the quotes from the integer value:

USE test;
INSERT INTO idk(Id, Name) VALUES (1,'Name');
0
1

Use single quotes

USE test;
 INSERT INTO idk(Id, Name) VALUES ('1','Name');

Also, this might help you out. If you right click on the Table, go to Script Table, and SSMS will generate scripts for you.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.