create table psw(职员ID int,姓名 varchar(10),psw varchar(10))
create table test(iid int identity,tid int,[text] varchar(10))
gocreate TRIGGER psw_Trigger_ins ON psw FOR INSERT 
AS 
begin 
  if (select count(*) from inserted where psw='1001')>0 
  insert test(tid,[text]) select 职员ID,'100101' from inserted where psw='1001' 
end 
goinsert into psw values(1, 'name1' , '1001')
insert into psw values(2, 'name2' , '1001')select * from testdrop table psw,test/*
iid         tid         text       
----------- ----------- ---------- 
1           1           100101
2           2           100101(所影响的行数为 2 行)
*/

解决方案 »

  1.   

    这样是可以的,当psw表中的主键[职员ID]不设为自动标识时没问题,但,设为自动标识时出错了.
      

  2.   


    create table psw(职员ID int identity,姓名 varchar(10),psw varchar(10))
    create table test(iid int identity,tid int,[text] varchar(10))
    gocreate TRIGGER psw_Trigger_ins ON psw FOR INSERT 
    AS 
    begin 
      if (select count(*) from inserted where psw='1001')>0 
      insert test(tid,[text]) select 职员ID,'100101' from inserted where psw='1001' 
    end 
    goinsert into psw(姓名,psw) values('name1' , '1001')
    insert into psw(姓名,psw) values('name2' , '1001')select * from testdrop table psw,test/*
    iid         tid         text       
    ----------- ----------- ---------- 
    1           1           100101
    2           2           100101(所影响的行数为 2 行)
    */
      

  3.   

    我是在ACCESS中直接打开数据表的,提示为:数据已添加到数据库中,但不能显示在窗体上,因为它不满足从属记录源中的条件!如果试图保存的数据正保存到 SQL 数据库(Microsoft SQL Server 7.0),并且子窗体的 RecordSource 使用的 SQL Select 语句中字段直接从源表拖出而来,同时表使用的“标识”字段设置为其主键,则会发生此错误。
    若要避免此问题,请将该子窗体的 RecordSource 属性设置为 Table 或 View。
    -或-
    升级到 Microsoft SQL Server 的更新版本。
    请联机查看有关此错误消息的详细信息。