简体   繁体   English

SQL Server 2000:限制行数

[英]SQL Server 2000: Limit number of rows

Is there a way to limit the number of rows in a SQL Server 2000 database, such that older rows are deleted when new ones come in? 有没有办法限制SQL Server 2000数据库中的行数,以便在新的行进入时删除旧行?

I have some data that I'd like to keep around for a about thirty days - after that, I don't care whether the data lays around or is deleted - as long as the table doesn't become huge. 我有一些数据,我想保留大约三十天 - 之后,我不关心数据是否存在或被删除 - 只要表格不会变大。

Any other suggestions or welcome - I'm decent with programming against a database, but I'm by no means a DBA. 任何其他建议或欢迎 - 我对数据库的编程很体面,但我绝不是一个DBA。

Thanks. 谢谢。

Not explicitly, no. 没有明确,没有。 However, you can set up a TRIGGER on the INSERT for the database to delete any rows older than thirty days (so you only delete rows as you add more, not just for the sake of it). 但是,您可以在INSERT为数据库设置TRIGGER以删除超过30天的任何行(因此,只有在添加更多行时才删除行,而不仅仅是为了它)。 Or, you can use SQL Server Agent and set up a Stored Procedure to do a 或者,您可以使用SQL Server代理并设置存储过程来执行操作

delete from table where insertdate <= dateadd(d, -30, getdate())

The typical way to do this would be to create a stored proc or a chunk of T-SQL code that deletes the old entries, and have this chunk of T-SQL run every night or every week or whatever you need. 这样做的典型方法是创建一个存储过程或一大块T-SQL代码来删除旧条目,并且每晚或每周运行这块T-SQL或任何你需要的东西。

There's no system-built-in way to limit the number of rows and have SQL Server toss out the oldest ones automatically. 没有系统内置的方法来限制行数,并让SQL Server自动抛出最旧的行。

MArc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM