标题:保存点不会用
取消只看楼主
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
结帖率:96.55%
已结贴  问题点数:20 回复次数:7 
保存点不会用
程序代码:
BEGIN TRANSACTION;
INSERT INTO ContactReason VALUES ('1001', '////');
INSERT INTO ContactReason VALUES ('1002', '????');
SAVE TRANSACTION savapoint_cc;
DELETE ContactReason WHERE ContactReason = 'yxf';
ROLLBACK TO SAVEPOINT savapoint_cc;
DML都是没有问题的
就是想问下最后那句怎么用
2011-05-16 14:58
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
得分:0 
回复 2楼 lxd0980
/*------------------------
BEGIN TRANSACTION;
INSERT INTO ContactReason VALUES ('1001', '////');
INSERT INTO ContactReason VALUES ('1002', '????');
SAVE TRANSACTION savapoint_cc;
DELETE ContactReason WHERE ContactReason = 'yxf';
ROLLBACK TO SAVEPOINT savapoint_cc;
------------------------*/
消息 156,级别 15,状态 1,第 6 行
关键字 'TO' 附近有语法错误。
2011-05-16 18:50
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
得分:0 
程序代码:
/*------------------------
INSERT INTO ContactReason VALUES ('1001', '////');
INSERT INTO ContactReason VALUES ('1002', '????');
DELETE ContactReason WHERE ContactReason = 'yxf';
------------------------*/

(1 行受影响)

(1 行受影响)

(0 行受影响)
是不是ROLLBACK这句写错啦???
2011-05-16 18:54
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
得分:0 
首先:我可以理解

但是在我的
上面运行 就是有错误
现在不明白 为什么会有错误
2011-05-16 19:52
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
得分:0 
像这样:
程序代码:
SELECT * FROM ContactReason;

BEGIN TRAN;
INSERT INTO ContactReason VALUES ('123', 'yyy');
SELECT * FROM ContactReason;
ROLLBACK;

SELECT * FROM ContactReason;
执行的结果:



这样子可以正确

所以现在就是问1楼的怎么会有错误  不知道现在说清楚没有
2011-05-16 19:56
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
得分:0 
。。。。
从头来过吧
假设什么都ok
现在在某个数据库当中
USE <database_name>
GO
存在ContactReason这样一张表
CREATE TABLE ContactReason
(
    ContactReason NVARCHAR(10),
    Description NVARCHAR(40),
    CONSTRAINT pk_contactreason PRIMARY KEY (ContactReason)
);
声明:上面标色的都没有问题 包括下面的DML语句也是没有问题的(即单独拿出来时可以的)

现在要问的问题:
第一 下面这段代码中有没有错误(主要是最后那句) ?
第二  如果没有错误是不是很有可能是我的运行环境不支持这样子的写法 ?
总结下: 如果不是语句本身的问题 引起我上面截图上的错误的可能性是什么?

BEGIN TRANSACTION;
INSERT INTO ContactReason VALUES ('1001', '////');
INSERT INTO ContactReason VALUES ('1002', '????');
SAVE TRANSACTION savapoint_cc;
DELETE ContactReason WHERE ContactReason = 'yxf';
ROLLBACK TO SAVEPOINT savapoint_cc;
2011-05-16 22:01
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
得分:0 
改动了下 这样行
程序代码:
USE master
GO

CREATE TABLE ContactReason
(
    ContactReason NVARCHAR(10),
    Description NVARCHAR(40),
    CONSTRAINT pk_contactreason PRIMARY KEY (ContactReason)
);

INSERT INTO ContactReason VALUES ('yxf', 'hhhhhhh');

BEGIN TRAN;
SELECT * FROM ContactReason;
INSERT INTO ContactReason VALUES ('1001', '///////');
INSERT INTO ContactReason VALUES ('1002', '???????');
SELECT * FROM ContactReason;
SAVE TRAN savepoint_first;
DELETE ContactReason WHERE ContactReason = 'yxf';
SELECT * FROM ContactReason;
ROLLBACK TRAN savepoint_first;
SELECT * FROM ContactReason;

DROP TABLE ContactReason;
GO

 
2011-05-17 18:35
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
得分:0 
看来是我开始的那条语句写错啦
2011-05-17 18:37



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-340047-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.347143 second(s), 9 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved