SQL Server 2005实用新特性
SQL Server 2005 相对于 SQL Server 2000 做了很大的改进,许些新 特性 是非常 实用 的。本文中将通过几个具体示例进行详细的说明。( 这些例子引用Northwind库) 1. TOP 表达式 SQL Server 2000的TOP是个固定值,是不是觉得差强人意,现在改进了。 --前n名的
SQL Server 2005相对于SQL Server 2000做了很大的改进,许些新特性是非常实用的。本文中将通过几个具体示例进行详细的说明。( 这些例子引用Northwind库)
1. TOP 表达式
SQL Server 2000的TOP是个固定值,是不是觉得差强人意,现在改进了。
--前n名的订单
declare @n int
set @n = 10
select TOP(@n) * from Orders
2. 分页
不知大家过去用SQL Server 2000是如何分页的,大多都用到了临时表。SQL Server 2005就支持分页,性能也非常不错。
--按Freight从小到大排序,求20到30行的结果
select * from(select OrderId, Freight, ROW_NUMBER() OVER(order by Freight) as row from Orders) a
where row between 20 and 30
3. 排名
select * from(select OrderId, Freight, RANK() OVER(order by Freight) as rank from Orders) a
where rank between 20 and 30
4. try ... catch
SQL Server 2000没有异常,T-SQL必须逐行检查错误代码,对于习惯了try catch程序员,2005是不是更加亲切:
SET XACT_ABORT ON -- 打开 try功能
BEGIN TRY
begin tran
insert into Orders(CustomerId) values(-1)
commit tran
print 'commited'
END TRY
BEGIN CATCH
rollback
print 'rolled back'
END CATCH
5. 通用表达式CTE
通过表达式可以免除你过去创建临时表的麻烦。
例:结合通用表达式进行分页
WITH OrderFreight AS(
select OrderId, Freight, ROW_NUMBER() OVER(order by Freight) as row from Orders
)
select OrderId, Freight from OrderFreight where row between 10 and 20
特别之处:通过表达式还可以支持递归.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

HQL and SQL are compared in the Hibernate framework: HQL (1. Object-oriented syntax, 2. Database-independent queries, 3. Type safety), while SQL directly operates the database (1. Database-independent standards, 2. Complex executable queries and data manipulation).

"Usage of Division Operation in OracleSQL" In OracleSQL, division operation is one of the common mathematical operations. During data query and processing, division operations can help us calculate the ratio between fields or derive the logical relationship between specific values. This article will introduce the usage of division operation in OracleSQL and provide specific code examples. 1. Two ways of division operations in OracleSQL In OracleSQL, division operations can be performed in two different ways.

Oracle and DB2 are two commonly used relational database management systems, each of which has its own unique SQL syntax and characteristics. This article will compare and differ between the SQL syntax of Oracle and DB2, and provide specific code examples. Database connection In Oracle, use the following statement to connect to the database: CONNECTusername/password@database. In DB2, the statement to connect to the database is as follows: CONNECTTOdataba

Practical tips for converting full-width English letters into half-width forms. In modern life, we often come into contact with English letters, and we often need to input English letters when using computers, mobile phones and other devices. However, sometimes we encounter full-width English letters, and we need to use the half-width form. So, how to convert full-width English letters to half-width form? Here are some practical tips for you. First of all, full-width English letters and numbers refer to characters that occupy a full-width position in the input method, while half-width English letters and numbers occupy a full-width position.

PyCharm Beginner's Guide: Practical Tips for Deleting Projects PyCharm is a powerful Python integrated development environment (IDE). When developing projects, sometimes you need to delete projects or files in the projects. This article will introduce practical techniques for deleting projects in PyCharm, and provide specific code examples to help novices better understand and apply. 1. Delete the project Deleting the project means deleting the entire project folder, which is very useful when we need to clean or rebuild the project. Delete in PyCharm

What is Identity in SQL? Specific code examples are needed. In SQL, Identity is a special data type used to generate auto-incrementing numbers. It is often used to uniquely identify each row of data in a table. The Identity column is often used in conjunction with the primary key column to ensure that each record has a unique identifier. This article will detail how to use Identity and some practical code examples. The basic way to use Identity is to use Identit when creating a table.

Interpretation of MyBatis dynamic SQL tags: Detailed explanation of Set tag usage MyBatis is an excellent persistence layer framework. It provides a wealth of dynamic SQL tags and can flexibly construct database operation statements. Among them, the Set tag is used to generate the SET clause in the UPDATE statement, which is very commonly used in update operations. This article will explain in detail the usage of the Set tag in MyBatis and demonstrate its functionality through specific code examples. What is Set tag Set tag is used in MyBati

Solution: 1. Check whether the logged-in user has sufficient permissions to access or operate the database, and ensure that the user has the correct permissions; 2. Check whether the account of the SQL Server service has permission to access the specified file or folder, and ensure that the account Have sufficient permissions to read and write the file or folder; 3. Check whether the specified database file has been opened or locked by other processes, try to close or release the file, and rerun the query; 4. Try as administrator Run Management Studio as etc.
