我刚学会的:USE pubs-- 创建表
IF EXISTS (SELECT name FROM sysobjects
      WHERE name = 'ConfinedTable' AND type = 'U')
   DROP TABLE confinedtable
GO
CREATE TABLE confinedtable ( name char(10), id int, note varchar(255) )-- 创建触发器
IF EXISTS (SELECT name FROM sysobjects
      WHERE name = 'trConfinedTable' AND type = 'TR')
   DROP TRIGGER trConfinedTable
GO
CREATE TRIGGER trConfinedTable
ON ConfinedTable
FOR INSERT
AS
/* Get the range of level for this job type from the jobs table. */
DECLARE @record_count int
SELECT @record_count = count(1)
FROM ConfinedTable
IF ( @record_count > 3 ) -- 最大记录数为3
BEGIN
   RAISERROR ('这张表只能保存3条记录.',16,1)
   ROLLBACK TRANSACTIONEND
GO
insert into ConfinedTable values ( 'abc1', 1, 'dir' )
insert into ConfinedTable values ( 'abc2', 2, 'format' )
insert into ConfinedTable values ( 'abc3', 3, 'debug' )
insert into ConfinedTable values ( 'abc4', 4, 'del' )select * from ConfinedTable