由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - How to merge tables in SQL Server 2000?
相关主题
Merge table with one single query?[转载] 真的没有人懂 ORACLE pro*c阿? :((((
MS T-SQL 问题Deadlock on merge (oracle)
SQL Server - how to obtain data type name如何判断一行是否存在的问题。
一个sql问题:怎样实现 (((a1*10)+a2)*10+a3)*10 ... (转载)How to get other columns after UNION?
2 SQL SERVER Sr SQL Programmer positions (转载)问一个SQL Server的问题
SQL run a stored procedure by fetching from a cursor row by rowerror of executing SQL query of string concatenation (转载
get value returned by SQLstored procedure from python (转载)SQL Server stupid questions
Re: 刚电面一个,fail了 (转载)SQL Server insert speed too slow! Help?
相关话题的讨论汇总
话题: sql话题: server话题: update话题: tbla话题: insert
进入Database版参与讨论
1 (共1页)
c**t
发帖数: 2744
1
like oracle or SQL Server 2008
MERGE INTO TblA USING TblB ON TblA.PK=TblB.PK
WHEN MATCHED THEN UPDATE ..
WHEN NOT MATCHED THEN INSERT ...
how to do it in SQL Server 2000?
Thinking to use cursor of TblB, then
UPDATE TblA set ... WHERE TblA.PK=Cursor.PK
if @@ERROR <> 0 then
INSERT INTO TblA ...
end
This worked, but seems too slow; any better way?
B*****g
发帖数: 34098
2
Don't know.
I tried something on oracle
First one seems work:
DECLARE
CURSOR lcurid IS
SELECT a.ID,
b.ID bid,
b.NAME bname
FROM t1 a, t2 b
WHERE a.ID(+) = b.ID
FOR UPDATE OF a.name;
BEGIN
FOR x IN lcurid
LOOP
IF x.id IS NULL THEN
INSERT INTO t1(ID, NAME)
VALUES(x.bid, x.bname);
ELSE
UPDATE t1 c
SET c.name = x.bname
WHERE current of lcurid;
END IF;
END LOOP;
END;
second one not work(error ora-01410:invalid row

【在 c**t 的大作中提到】
: like oracle or SQL Server 2008
: MERGE INTO TblA USING TblB ON TblA.PK=TblB.PK
: WHEN MATCHED THEN UPDATE ..
: WHEN NOT MATCHED THEN INSERT ...
: how to do it in SQL Server 2000?
: Thinking to use cursor of TblB, then
: UPDATE TblA set ... WHERE TblA.PK=Cursor.PK
: if @@ERROR <> 0 then
: INSERT INTO TblA ...
: end

c**t
发帖数: 2744
3
if in oracle why not just simply use merge?

【在 B*****g 的大作中提到】
: Don't know.
: I tried something on oracle
: First one seems work:
: DECLARE
: CURSOR lcurid IS
: SELECT a.ID,
: b.ID bid,
: b.NAME bname
: FROM t1 a, t2 b
: WHERE a.ID(+) = b.ID

B*****g
发帖数: 34098
4
for test only

【在 c**t 的大作中提到】
: if in oracle why not just simply use merge?
j*****n
发帖数: 1781
5
gee, update with inner join, insert with left join...
how difficult job is?
B*****g
发帖数: 34098
6
只准scan table一次,哈哈

【在 j*****n 的大作中提到】
: gee, update with inner join, insert with left join...
: how difficult job is?

1 (共1页)
进入Database版参与讨论
相关主题
SQL Server insert speed too slow! Help?2 SQL SERVER Sr SQL Programmer positions (转载)
HELP! SQL Server vs JDBC questionSQL run a stored procedure by fetching from a cursor row by row
怎么学SQL SERVERget value returned by SQLstored procedure from python (转载)
老印给我的一个ChallengeRe: 刚电面一个,fail了 (转载)
Merge table with one single query?[转载] 真的没有人懂 ORACLE pro*c阿? :((((
MS T-SQL 问题Deadlock on merge (oracle)
SQL Server - how to obtain data type name如何判断一行是否存在的问题。
一个sql问题:怎样实现 (((a1*10)+a2)*10+a3)*10 ... (转载)How to get other columns after UNION?
相关话题的讨论汇总
话题: sql话题: server话题: update话题: tbla话题: insert