简体   繁体   English

在 Azure SQL 数据库中使用“INSERT INTO”SQL 查询时出错

[英]Error During using “INSERT INTO” SQL Query in Azure SQL Database

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.我创建了一个 Azure SQL 服务器和 SQL 数据库,以及该数据库中的一个表,名为 table1,列 ID、FirstName、LastName。 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) (顺便说一句:ID 是 int 类型,所有其他都是 varchar 类型)

Shouldn't the above SQL query in SQL Server insert the new row in that table? SQL 服务器中的上述 SQL 查询不应该在该表中插入新行吗?

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:在标准 SQL 中,双引号代表列名 - 因此您得到的错误是:

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).此外,假设DOB是类似date的数据类型,您应该考虑使用更标准的格式(例如YYYY-MM-DDYYYYMMDD )而不是依赖服务器推断格式的能力(尽管 SQL 服务器确实是擅长)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM