I have created an Azure SQL Server with SQL Database, as well as a table in that database named table1 with columns ID, FirstName, LastName, and DOB. However, when I try to use this statement:
INSERT INTO table1(ID, FirstName, LastName, DOB)
VALUES (1, "Rohit", "Karthik", "8/2/06")
it outputs an error:
Failed to execute query. Error: Invalid column name 'Rohit'.
Invalid column name 'Karthik'.
Invalid column name '8/2/06'.
(BTW: ID is of type int, and all the others are of type varchar)
Shouldn't the above SQL query in SQL Server insert the new row in that table?
I am not sure why this error is coming, please help.
Use single quotes for literal strings. In standard SQL, double quotes stand for column names - hence the error that you are getting:
INSERT INTO table1(ID, FirstName, LastName, DOB)
VALUES (1, 'Rohit', 'Karthik', '8/2/06')
Also, assuming that DOB is of a date-like datatype, you should consider using a more standard format (such as YYYY-MM-DD, or YYYYMMDD) instead of relying on your server's ability to infer the format (although SQL Server is really good at it).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With