As there is Rowcount and Rownum in Oracle to identify rows in a table, what is available in SQL Server?

    Requires Free Membership to View

You have ROWCOUNT, which is a session-level global variable. You can check this value after an insert, update, delete or select and it will return the number of rows affected by the last statement. As for row numbers you will have to work with SQL Server 2005 to take advantage of this new feature. If you are running SQL Server 2005 and installed the AdventureWorks database, here's an example:

The ROW_NUMBER function returns the ordinal row position of each row in a grouping within a result set. This function can be very useful for generating reports.

 select ROW_NUMBER() over(PARTITION BY PC.Name ORDER BY ListPrice) as Row, PC.Name Category, P.Name Product, P.ListPrice From Production.Product P JOIN Production.ProductSubcategory PSC on P.ProductSubCategoryID = PSC.ProductSubCategoryID JOIN Production.ProductCategory PC on PSC.ProductCategoryID = PC.ProductCategoryID

This was first published in June 2006

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: