--删除学生信息declare @tran_name varchar(30),@StuId char(10)
select @tran_name = 'students_delete'
@StuId = '2010121009' 
begin tran @tran_namego
delete from dbo.Students where dbo.Students.cStudentsId = @StuId
go
delete from dbo.StudentsSchool where dbo.StudentsSchool.cStudentsId = @StuId
go
delete from dbo.StuSchoolRewardPunish where dbo.StuSchoolRewardPunish.cStudentsId = @StuId
go 
delete from dbo.Stuusers where dbo.Stuusers.cStudentsId = @StuId
go 
delete from dbo.StudentContact where dbo.StudentContact.cStudentsId = @StuId
go 
delete from dbo.ApplyJobInformation where dbo.ApplyJobInformation.cStudentsId = @StuId
go 
delete from dbo.Education where dbo.Education.cStudentsId = @StuId
go 
delete from dbo.IntroduceYourself where dbo.IntroduceYourself.cStudentsId =--删除学生信息declare @tran_name varchar(30),@StuId char(10)
select @tran_name = 'students_delete'
@StuId = '2010121009' 
begin tran @tran_namego
delete from dbo.Students where dbo.Students.cStudentsId = @StuId
go
delete from dbo.StudentsSchool where dbo.StudentsSchool.cStudentsId = @StuId
go
delete from dbo.StuSchoolRewardPunish where dbo.StuSchoolRewardPunish.cStudentsId = @StuId
go 
delete from dbo.Stuusers where dbo.Stuusers.cStudentsId = @StuId
go 
delete from dbo.StudentContact where dbo.StudentContact.cStudentsId = @StuId
go 
delete from dbo.ApplyJobInformation where dbo.ApplyJobInformation.cStudentsId = @StuId
go 
delete from dbo.Education where dbo.Education.cStudentsId = @StuId
go 
delete from dbo.IntroduceYourself where dbo.IntroduceYourself.cStudentsId = @StuId
go
commite tran 'students_delete'go
commite tran 'students_delete'
各位,我要删除--删除学生信息declare @tran_name varchar(30),@StuId char(10)
select @tran_name = 'students_delete'
@StuId = '2010121009' 
begin tran @tran_namego
delete from dbo.Students where dbo.Students.cStudentsId = @StuId
go
delete from dbo.StudentsSchool where dbo.StudentsSchool.cStudentsId = @StuId
go
delete from dbo.StuSchoolRewardPunish where dbo.StuSchoolRewardPunish.cStudentsId = @StuId
go 
delete from dbo.Stuusers where dbo.Stuusers.cStudentsId = @StuId
go 
delete from dbo.StudentContact where dbo.StudentContact.cStudentsId = @StuId
go 
delete from dbo.ApplyJobInformation where dbo.ApplyJobInformation.cStudentsId = @StuId
go 
delete from dbo.Education where dbo.Education.cStudentsId = @StuId
go 
delete from dbo.IntroduceYourself where dbo.IntroduceYourself.cStudentsId = @StuId
go
commite tran 'students_delete'各位, 我要删除 @StuId = 2010121009的所有表中有关的行记录,但是执行的时候老是有 @StuId没有声明,那么声明该写在哪里呢,谢谢,各位高手指点一二

解决方案 »

  1.   

    你加那么多go搞什么,都在一个事务里,把go去掉,后面的@StuId明显在很多批处理中,怎么能访问到啊
      

  2.   

    declare @tran_name varchar(30),@StuId char(10)
    select @tran_name = 'students_delete'
    @StuId = '2010121009'   
    begin tran @tran_namedelete from dbo.Students where dbo.Students.cStudentsId = @StuIddelete from dbo.StudentsSchool where dbo.StudentsSchool.cStudentsId = @StuIddelete from dbo.StuSchoolRewardPunish where dbo.StuSchoolRewardPunish.cStudentsId = @StuId
     
    delete from dbo.Stuusers where dbo.Stuusers.cStudentsId = @StuId
     
    delete from dbo.StudentContact where dbo.StudentContact.cStudentsId = @StuIddelete from dbo.ApplyJobInformation where dbo.ApplyJobInformation.cStudentsId = @StuIddelete from dbo.Education where dbo.Education.cStudentsId = @StuIddelete from dbo.IntroduceYourself where dbo.IntroduceYourself.cStudentsId = @StuIdcommite tran 'students_delete'
      

  3.   

    declare @tran_name varchar(30),@StuId char(10)
    select @tran_name = 'students_delete'
    @StuId = '2010121009'   
    begin tran @tran_namedelete from dbo.Students where dbo.Students.cStudentsId = @StuIddelete from dbo.StudentsSchool where dbo.StudentsSchool.cStudentsId = @StuIddelete from dbo.StuSchoolRewardPunish where dbo.StuSchoolRewardPunish.cStudentsId = @StuId
     
    delete from dbo.Stuusers where dbo.Stuusers.cStudentsId = @StuId
     
    delete from dbo.StudentContact where dbo.StudentContact.cStudentsId = @StuIddelete from dbo.ApplyJobInformation where dbo.ApplyJobInformation.cStudentsId = @StuIddelete from dbo.Education where dbo.Education.cStudentsId = @StuIddelete from dbo.IntroduceYourself where dbo.IntroduceYourself.cStudentsId = @StuIdcommite 
      

  4.   

    能不能不给@StuId赋值,先搞成一个变量,像存储过过程,等到执行的时候再给@StuId赋值呢,又该怎么写呢,非常感激……
      

  5.   

    create proc pr_name(@StuId char(10))
    as
    begin
    begin tran t1delete from dbo.Students where dbo.Students.cStudentsId = @StuIddelete from dbo.StudentsSchool where dbo.StudentsSchool.cStudentsId = @StuIddelete from dbo.StuSchoolRewardPunish where dbo.StuSchoolRewardPunish.cStudentsId = @StuId
     
    delete from dbo.Stuusers where dbo.Stuusers.cStudentsId = @StuId
     
    delete from dbo.StudentContact where dbo.StudentContact.cStudentsId = @StuIddelete from dbo.ApplyJobInformation where dbo.ApplyJobInformation.cStudentsId = @StuIddelete from dbo.Education where dbo.Education.cStudentsId = @StuIddelete from dbo.IntroduceYourself where dbo.IntroduceYourself.cStudentsId = @StuIdcommite tran 'students_delete'
    endexec pr_name '2010121009'
      

  6.   

    commite tran 'students_delete'改为===》commite即可
      

  7.   


    declare @tran_name varchar(30),@StuId char(10)
    select @tran_name = 'students_delete',
    @StuId = '2010121004' 
    begin tran @tran_name
    delete from dbo.Students where dbo.Students.cStudentsId = @StuId
    delete from dbo.StudentsSchool where dbo.StudentsSchool.cStudentsId = @StuId
    delete from dbo.StuSchoolRewardPunish where dbo.StuSchoolRewardPunish.cStudentsId = @StuId
    delete from dbo.Stuusers where dbo.Stuusers.cStudentsId = @StuId
    delete from dbo.StudentContact where dbo.StudentContact.cStudentsId = @StuId
    delete from dbo.ApplyJobInformation where dbo.ApplyJobInformation.cStudentsId = @StuId
    delete from dbo.Education where dbo.Education.cStudentsId = @StuId
    delete from dbo.IntroduceYourself where dbo.IntroduceYourself.cStudentsId = @StuId
    commit tran @tran_name
    消息 547,级别 16,状态 0,第 6 行
    DELETE 语句与 REFERENCE 约束"fkStuusers"冲突。该冲突发生于数据库"StudentsJobSystem",表"dbo.Stuusers", column 'cStudentsId'。这个又该怎么解决呢,谢谢……
      

  8.   

    Stuusers的cStudentsId主键字段被后面所有的表引用作为外键了,你应该先删除后面的  
      

  9.   

    declare @tran_name varchar(30),@StuId char(10)
    select @tran_name = 'students_delete',
    @StuId = '2010121004'  
    begin tran @tran_namedelete from dbo.StudentsSchool where dbo.StudentsSchool.cStudentsId = @StuId
    delete from dbo.StuSchoolRewardPunish where dbo.StuSchoolRewardPunish.cStudentsId = @StuId
    delete from dbo.Stuusers where dbo.Stuusers.cStudentsId = @StuId
    delete from dbo.StudentContact where dbo.StudentContact.cStudentsId = @StuId
    delete from dbo.ApplyJobInformation where dbo.ApplyJobInformation.cStudentsId = @StuId
    delete from dbo.Education where dbo.Education.cStudentsId = @StuId
    delete from dbo.IntroduceYourself where dbo.IntroduceYourself.cStudentsId = @StuId
    ---删除Students 放在后面
    delete from dbo.Students where dbo.Students.cStudentsId = @StuId
    commit tran @tran_name
      

  10.   


    这一段放在最后删除delete from dbo.Students where dbo.Students.cStudentsId = @StuId--
      

  11.   

    相同贴发一贴就行了
    这一段放在最后删除delete from dbo.Students where dbo.Students.cStudentsId = @StuId--