create proc proc_aa
as
BEGIN TRAN
set nocount on
set ansi_warnings off
insert into B select * from A
IF @@ERROR<>0 GOTO errhandle
COMMIT TRAN
SELECT 1errhandle:
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
SELECT 0
ENDGO--成功返回1,失敗返回0
as
BEGIN TRAN
set nocount on
set ansi_warnings off
insert into B select * from A
IF @@ERROR<>0 GOTO errhandle
COMMIT TRAN
SELECT 1errhandle:
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
SELECT 0
ENDGO--成功返回1,失敗返回0
如果量表结构相同,但若两个表中都有自动编号字段那就不可以,如a要导入到b,若a,b都有自动编号字段,把a的自动编号字段去掉就可以,若a的自动编号作关键字,呵呵,你的麻烦就大了
2.BCP也可以啊
as
BEGIN TRAN--->開始一個事務
set nocount on --->不返回信息
set ansi_warnings off --->錯誤不警告
insert into B select * from A
IF @@ERROR<>0 GOTO errhandle -->發生錯誤跳轉到errhandle
COMMIT TRAN -->不發生錯誤就提交事務
SELECT 1errhandle:
IF @@ERROR<>0 -->@@ERROR是全局變量,發生錯誤時不等於0
BEGIN
ROLLBACK TRAN---->發生錯誤回滾到原來狀態
SELECT 0
ENDGO