All of Query was successfully tested and running well on Microsoft SQL Server 2008

Kamis, 23 Agustus 2012

sql autonumber

Use table_accessories which created lesson before

select * from table_accessories order by product_name asc

#Results:
product_name
Keyboard
Keypad
Monitor
Mouse
Printer

select Row_Number() over (order by product_name asc)autoNum,* from table_accessories

#Results:
autoNum   product_name
1         Keyboard
2         Keypad
3         Monitor
4         Mouse
5         Printer

Notes:
order by product_name asc: ascending ordering
order by product_name desc: descending ordering
Row_Number() over (order by product_name asc):
autonumber base on product_name ascending ordering


Tidak ada komentar:

Posting Komentar