Sql-server – Inserting into Microsoft SQL Server Table

sql servert-sql

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.

Best Answer

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');