Create Table "Users"(
"UsersId" int identity(1,1) not null,
"UsersName" varchar(50) not null,
"Password" varchar(32) not null,
constraint PK_Users primary key ("UsersId"),
);现在我要建一个插入的同时增加修改时间的存储过程,请就高手指点!

解决方案 »

  1.   

    --> 测试数据:[ta]
    if object_id('[ta]') is not null drop table [ta]
    go
    create table [ta]([id] int identity,[name] varchar(4),[pwd] int)--> 测试数据:[tb]
    if object_id('[tb]') is not null drop table [tb]
    go
    create table [tb]([id] int,[login_time] datetime)
    insert [tb]
    select 1,'2010-05-09'--------------------------------查询开始------------------------------select * from [tb]
    create trigger t_user on ta
    for insert
    as
    begin
    update tb set [login_time]=getdate() from inserted i,tb b where i.id=b.id
    end
    --测试
    insert [ta]
    select '张三',123456select * from tb
    /*
    id          login_time
    ----------- -----------------------
    1           2010-05-09 16:35:34.160(1 行受影响)*/