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.
-
Welcome to the world of standard SQL.mustaccio– mustaccio2017年05月20日 15:14:33 +00:00Commented May 20, 2017 at 15:14
2 Answers 2
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');
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.