SQL 2008:最后30个输入记录 [英] SQL 2008: last 30 entered records

查看:79
本文介绍了SQL 2008:最后30个输入记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL SERVER 2008的新手



如何使用Sql命令/语句在数据库中获取最后30条记录



先谢谢

Am new to SQL SERVER 2008

How can i get the last 30 entered record on a database using Sql commands/statements

Thanks in Advance

推荐答案

保证最后输入的唯一方法是在创建记录时给记录加时间戳,但包括表中的datetime列。这允许您在选择查询中使用ORDER BY子句,然后返回前30个结果:

The only way to guarantee getting the last entered is to timestamp the records when you create them, but including a datetime column in the table. This allows you to use the ORDER BY clause in your select query, and then return the top 30 results:
SELECT TOP 30 * FROM MyTable ORDER BY EnteredAt DESC

如果你不提供ORDER BY,那么SQL可以自由地以任何顺序返回记录如果发现方便(通常,它是修改顺序,但是不能保证,特别是如果记录是删除并稍后重用该空间)

If you don''t supply ORDER BY, the SQL is at liberty to return records in any order if finds convenient (normally, it''s in modification order, but it''s not guaranteed, particularly if records are deleted and the space is reused later)


这篇关于SQL 2008:最后30个输入记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆