簡體   English   中英

'`'附近的SQL Server語法不正確

[英]SQL Server Incorrect syntax near '`'

我嘗試在Microsoft SQL Server上執行以下SQL。

$rs = odbc_exec($conn, "INSERT INTO tGuest (`GuestName`, `GuestEmailAddress`, `GuestPassword`, `GuestCity`, `GuestCountry`) VALUES ('test', 'test', 'test', 'test', 'test');");

但是我弄錯了以下錯誤:

[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '`'.

我看不到SQL代碼有什么問題,所以不確定是否丟失了某些內容或其他錯誤。

SQL Server使用[] / "引用標識符

分隔標識符

雙引號(“)或方括號([])括起來 ,符合標識符格式規則的標識符可能不會被定界。

$rs = odbc_exec($conn, "INSERT INTO tGuest ([GuestName], [GuestEmailAddress], [GuestPassword], [GuestCity], [GuestCountry]) VALUES ('test', 'test', 'test', 'test', 'test');");

在您的情況下,您也可以完全跳過它,因為您的標識符有效:

INSERT INTO tGuest(GuestName,GuestEmailAddress,GuestPassword,GuestCity,GuestCountry) 
VALUES ('test', 'test', 'test', 'test', 'test');

您的命名約定似乎是多余的。 如果表名為tGuest則無需在Guest列前添加前綴。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM