开发者

sql - Insert between two rows?

开发者 https://www.devze.com 2023-02-19 10:20 出处:网络
I wis开发者_如何学JAVAh to know how I can insert a row between the two rows of a table. I am using MS-SQL and SQL management studio.

I wis开发者_如何学JAVAh to know how I can insert a row between the two rows of a table. I am using MS-SQL and SQL management studio.

Any help will be much appreciated.


If you do just a

SELECT (columns) FROM dbo.MyTable

there is no guaranteed order in the output - it might look like it's ordered, but there's no guarantee for anything.

If you want to order by something, you need to explicitly specify that by adding an ORDER BY clause to your statement:

SELECT (cols) FROM dbo.MyTable ORDER BY FirstName

Therefore, you cannot "insert" a new row between two other rows - it will just show up wherever it belongs, based on the order you've defined


You can order the rows according to the column values in ascending or descending order

SELECT * FROM tbl_newsletter ORDER BY newsletter_email ASC

here the rows are ordered in ascending order of the column newsletter_email

You can use DESC for ordering in descending order.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号