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.

joanolo
13.7k8 gold badges39 silver badges67 bronze badges
asked May 19, 2017 at 23:43
1
  • Welcome to the world of standard SQL. Commented 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');
ypercubeTM
99.7k13 gold badges217 silver badges306 bronze badges
answered May 19, 2017 at 23:53
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

ypercubeTM
99.7k13 gold badges217 silver badges306 bronze badges
answered May 19, 2017 at 23:54

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.