你都没有条件,肯定update 所有的.
update test set 年龄=年龄+1
where 姓名 in select 姓名 from inserted

解决方案 »

  1.   

    CREATE TABLE [test] (
      [id] [int] IDENTITY (1, 1) NOT NULL ,
      [姓名] [varchar] (8) COLLATE Chinese_PRC_CI_AS NULL ,
      [年龄] [int] NULL ,
      CONSTRAINT [PK_test] PRIMARY KEY  CLUSTERED 
      (
        [id]
      )
    )
    GOCREATE TABLE [tests] (
      [id] [int] ,
      [姓名] [varchar] (8) COLLATE Chinese_PRC_CI_AS NULL ,
      [年龄] [int] NULL ,
      CONSTRAINT [PK_tests] PRIMARY KEY  CLUSTERED 
      (
        [id]
      ),
     FOREIGN KEY (FK_ID) REFERENCES test (id) 
    )
    GOCREATE TRIGGER testtri ON dbo.test 
    FOR UPDATE 
    AS
    update tests set  姓名=inserted.姓名,  年龄=inserted.年龄 from inserted where tests.id=inserted.id
    go
      

  2.   

    大力大大,可以不用ID这个字段吗?
    为什么用tests.姓名=deleted.姓名不行呢?
      

  3.   

    在test表上建触发器
    [code]
    CREATE TRIGGER testtri ON dbo.test 
    FOR UPDATE 
    AS
    update tests set
      姓名=inserted.姓名,
      年龄=inserted.年龄
    from tests,deleted,inserted
    where tests.姓名=inserted.姓名
    [/code]就行了,因为update test set 年龄=年龄+1执行之后
    表deleted内容如下:
    张三  1
    李四  2
    王五  3
    赵六  4
    表inserted内容如下:
    张三  2
    李四  3
    王五  4
    赵六  5
      

  4.   

    where tests.姓名=inserted.姓名
    ?
    但是如果我update了姓名的值的话这样就会出错呀?
      

  5.   

    CREATE TRIGGER testtri ON dbo.test 
    FOR UPDATE 
    AS
    update tests set
      姓名=inserted.姓名,
      年龄=inserted.年龄
    from tests,inserted
    where tests.姓名=inserted.姓名
      

  6.   

    为什么 chenqinzeng(chenqinzeng) 和 happy_0325(快乐) 都要使用 “where tests.姓名=inserted.姓名”呢如果这样写的话,执行update test set 姓名=姓名 + '人'的话,就不对了
      

  7.   

    这个也是很容易的,编写触发器的时候deleted是存放删除掉的记录和修改过旧的记录,而inserted是存放新增加的数据和修改过新的数据,这下你应该可以自己搞定了吧