我想让数据表table1的记录数不能超过300条,这触发器怎么写?

解决方案 »

  1.   

    create   TRIGGER [触发器名] ON [dbo].[table1]
    FOR INSERT
    AS
     declare @r int
     select @r=count(*) from table1
     if @r>300
       delete table1 where id=(select  top 1 ID from table1)
      

  2.   

    CREATE TRIGGER CheckRecordCount ON [dbo].[Table1] 
    FOR INSERT
    AS
    begin
     Declare @count  int
     select @count=count(*) from  Table1 
     if (@count>300)
     Raiserror('不能超过300条记录',16,1)
     Rollback tran
    end