[英]How to understand where the error is in a SQL query that fails with this message Syntax error near 'INSERT INTO `
如果表中沒有名為“Orders”的記錄,我需要運行 SQL 查詢,該查詢會在表中插入一些內容。 到目前為止,我這樣做了:
IF NOT EXISTS (
SELECT
*
FROM
gridconfigs
WHERE
gridconfigs.name = 'Orders'
)
INSERT INTO
`gridconfigs` (
`ownerId`,
`classId`,
`name`,
`searchType`,
`type`,
`config`,
`description`,
`creationDate`,
`modificationDate`,
`shareGlobally`
)
VALUES(
....
這是我得到的錯誤:
Errore nella query (1064): Syntax error near 'INSERT INTO `gridconfigs` ( `ownerId`, `classId`, `name`, ...' at line 9
我不明白arror實際上是什么。
您可以使用 EXISITS 編寫 SELCT,而不是 INSERT INTO VLAUES
CREATE TABLE `gridconfigs` (
`ownerId` int,
`classId` int,
`name` varchar(19),
`searchType` int,
`type` int,
`config` int,
`description` int,
`creationDate` int,
`modificationDate` int,
`shareGlobally` int
)
;
INSERT INTO gridconfigs
VALUES
(1,2,'Orders',4,5,6,7,8,9,10)
;
INSERT INTO
`gridconfigs` (
`ownerId`,
`classId`,
`name`,
`searchType`,
`type`,
`config`,
`description`,
`creationDate`,
`modificationDate`,
`shareGlobally`
)
SELECT
1,2,3,4,5,6,7,8,9,10
WHERE NOT EXISTS ( SELECT 1 FROM gridconfigs WHERE gridconfigs.name = 'Orders')
Records: 0 Duplicates: 0 Warnings: 0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.