我有两个完全相同的SQL脚本。 第一个适用于PostrgeSQL,第二个适用于SQL-Server。
的PostgreSQL:
UPDATE address AS a
SET countrycode = s.isocode
FROM country AS s
WHERE a.idcountry = s.id;
SQL-服务器:
UPDATE a
SET a.countrycode = c.isocode
FROM address AS a
INNER JOIN country AS c
ON a.idcountry = c.id;
是否可以创建具有在两个数据库系统上运行的相同功能的单个脚本?
答案 0 :(得分:1)
尝试:
UPDATE address a
SET countrycode = (
SELECT s.isocode
FROM country s
WHERE a.idcountry = s.id
);