谁知道怎样判断表里面有没这条数据,如果没就添加有就更新
我在网上找了很多都不行我想可以再数据库里面运行sql但下面的老是不成功IF EXISTS (SELECT * FROM `ve123_links` WHERE `url`="xxxx") update `ve123_links` set `tuiguang`='1' where `url`='xxxx' ELSE BEGIN INSERT INTO `ve123_links`(`title`,`url`,`keywords`,`description`,`fulltxt`,`pic`,`nianfen`,`yuyan`,`diqu`,`zhuantai`) VALUES ('1','1','1','1','1','1','1','1','1','1') end
谁能矫正上面的语句
我在网上找了很多都不行我想可以再数据库里面运行sql但下面的老是不成功IF EXISTS (SELECT * FROM `ve123_links` WHERE `url`="xxxx") update `ve123_links` set `tuiguang`='1' where `url`='xxxx' ELSE BEGIN INSERT INTO `ve123_links`(`title`,`url`,`keywords`,`description`,`fulltxt`,`pic`,`nianfen`,`yuyan`,`diqu`,`zhuantai`) VALUES ('1','1','1','1','1','1','1','1','1','1') end
谁能矫正上面的语句
12.2.7. REPLACE Syntax
REPLACE [LOW_PRIORITY | DELAYED]
[INTO] tbl_name [(col_name,...)]
{VALUES | VALUE} ({expr | DEFAULT},...),(...),...Or: REPLACE [LOW_PRIORITY | DELAYED]
[INTO] tbl_name
SET col_name={expr | DEFAULT}, ...Or: REPLACE [LOW_PRIORITY | DELAYED]
[INTO] tbl_name [(col_name,...)]
SELECT ...12.2.5.3. INSERT ... ON DUPLICATE KEY UPDATE Syntax
If you specify ON DUPLICATE KEY UPDATE, and a row is inserted that would cause a duplicate value in a UNIQUE index or PRIMARY KEY, an UPDATE of the old row is performed. For example, if column a is declared as UNIQUE and contains the value 1, the following two statements have identical effect: INSERT INTO table (a,b,c) VALUES (1,2,3)
ON DUPLICATE KEY UPDATE c=c+1;
免费手册中有完整的例子和说明。