在 SQL 中为表行设置限制 [英] Set Limit for a Table Rows In SQL
本文介绍了在 SQL 中为表行设置限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为我的表的行设置限制.我该怎么做?
I want to set the limit for my table's rows. How can I do it?
例如我的表中有 50 行.
For example 50 rows in my table.
推荐答案
在表上创建一个 AFTER INSERT
触发器.以下是对您的要求相对有效的内容:
Create an AFTER INSERT
trigger on the table. Here's something that would be relatively effective with your requirement:
create trigger LimitTable
on YourTableToLimit
after insert
as
declare @tableCount int
select @tableCount = Count(*)
from YourTableToLimit
if @tableCount > 50
begin
rollback
end
go
这篇关于在 SQL 中为表行设置限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文