日期:2014-05-18 浏览次数:20485 次
declare @Name nvarchar(50) ='aclie', @Birthday nvarchar(50) ='2011-1-1', @StaData nvarchar(50) = '2011-1-1', @Gender nvarchar(50) ='男', @Nation nvarchar(50)='维吾尔族', @BodyID nvarchar(50)='123456789123456789' insert into Stu_info (Name,Birthday,StaData,Gender,Nation,BodyID) values (@Name,@Birthday,@StaData,@Gender,@BodyID) ; insert into StuAcct (SName,SPwd,StuId) select StuID,Name,RIGHT(BodyID,6) StuAcct from Stu_info where BodyID=@BodyID
触发器
------解决方案--------------------
这个可以做个判断
如果条件符合同时添加
------解决方案--------------------
declare @Name nvarchar(50)
declare @Birthday nvarchar(50)
declare @StaData nvarchar(50)
declare @Gender nvarchar(50)
declare @Nation nvarchar(50
declare @BodyID nvarchar(50
set @Name ='aclie'
set @Birthday ='2011-1-1'
set @StaData = '2011-1-1'
set @Gender ='男'
set @Nation ='维吾尔族'
set @BodyID ='123456789123456789'
insert into Stu_info (Name,Birthday,StaData,Gender,Nation,BodyID) values (@Name,@Birthday,@StaData,@Gender,@Nation,@BodyID) ;
insert into StuAcct (SName,SPwd,StuId) select StuID,Name,RIGHT(BodyID,6) from Stu_info where BodyID=@BodyID
------解决方案--------------------
呼叫水哥
------解决方案--------------------
是不是写个事务处理,tabel1 insert成功了然后提取第一个的信息添加进tabel2
------解决方案--------------------
create table tb1 ( id int identity(1,1), name varchar(10) ) create table tb2 ( id int , name varchar(10) ) declare @name nvarchar(10); set @name = 'aaa'; insert into tb1 values(@name) insert into tb2 select * from tb1 where name = @name select * from tb1 select * from tb2 /* id,name 1,aaa (1 行受影响) id,name 1,aaa (1 行受影响)
------解决方案--------------------
再加一个条件
insert into tb2 select * from tb1 where name = @name and id = @@identity
------解决方案--------------------