我需要更新记录的主键,但它也是另外两个表中的外键.我还需要更新的主键也反映在子表中.
这是我的查询和错误:
begin tran
update question set questionparent = 10000, questionid= 10005 where questionid = 11000;Run Code Online (Sandbox Code Playgroud)
Error 9/4/2009 10:04:49 AM 0:00:00.000 SQL Server Database Error: The UPDATE statement conflicted with the REFERENCE constraint "FK_GoalRequirement_Question". The conflict occurred in database "numgmttest", table "dbo.GoalRequirement", column 'QuestionID'. 14 0
我不记得该怎么做这就是为什么我在这里.有帮助吗?
我正在尝试使用一个过程(没有参数)来删除程序启动过程中位于模式中的所有用户创建的数据库对象,但我真的不确定如何解决这个问题.这是我到目前为止所拥有的,但我认为我的方式是错误的.
create or replace procedure CLEAN_SCHEMA is
cursor schema_cur is
select 'drop '||object_type||' '|| object_name|| DECODE(OBJECT_TYPE,'TABLE',' CASCADE CONSTRAINTS;',';')
from user_objects;
schema_rec schema_cur%rowtype;
begin
select 'drop '||object_type||' '|| object_name|| DECODE(OBJECT_TYPE,'TABLE',' CASCADE CONSTRAINTS;',';')
into schema_rec
from user_objects;
end;
/
我有一个问题,这个查询语句让我在结果中重复使用GoalText.有任何想法吗?
完整的查询语句:
Select g.GoalText, convert(nvarchar, g.GoalID) + '|' + convert(nvarchar, r.GoalReqID) as GoalID, GoalReqID
from Goal g inner join GoalRequirement r
on g.GoalID = r.GoalID
where GoalReqID in
(Select GoalReqID
from GoalRequirement r inner join SurveyAnswer a
on r.QuestionID = a.QuestionID and ReqQuestionValue = SurveyAnswer
where a.CycleID = 93 and ReqBMILevel is null
and ReqEnergyBalance is null and SurveyAnswer = 1 and r.QuestionID in
(Select QuestionID from Question where QuestionParent = 6000));Run Code Online (Sandbox Code Playgroud)
结果:
GoalText GoalID GoalReqID Choose lasagna, ravioli, stuffed …