如何将数据前缀添加到表中 [英] How to prefix data to a table

查看:60
本文介绍了如何将数据前缀添加到表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜欢使用INSERT INTO将数据附加到表的末尾吗?

Like using INSERT INTO does by appending data to the end of a table?

UPDATE [db].[schm].[table] SET [col] = ''new data'' WHERE [idx] = 1 



覆盖。使用TSQL必须有一个非常简单的方法。


Overwrites. There must be a singularly simple way to go about doing this using TSQL.

推荐答案

不,没有。



存储在SQL服务器(以及几乎所有其他数据库)中的记录顺序完全取决于SQL服务器 - 您无法以任何方式影响它,因为数据以最有效的方式物理存储SQL的特定版本,数据所需的索引以及数据本身。同样地,除非你另外告诉它,否则SQL服务器可以按照它认为合适的任何顺序返回行 - 不是按时间顺序输入的顺序,而不是你上次获得的顺序,而是它想要的任何顺序。



您可以在使用SELECT语句的任何时候指定记录的返回顺序 - 只需添加 ORDER BY子句 [ ^ 并且SQL将返回完全按照您要求的方式排序的行,并且每次都会返回相同的订单记录,直到您添加,删除或更改行数据。但是你不能影响他们存储的顺序,只是一点点。
No, there isn''t.

The order of records stored in SQL server (and pretty much all other databases) is solely up to SQL server - you cannot influence it in any way as the data is physically stored in the way which is most efficient for the particular version of SQL, the indexes the data needs, and the data itself. Similarly, unless you tell it otherwise, SQL server is at liberty to return rows in any order it finds suitable - not the order you entered them chronologically, not the order you last got them, but any order it wants.

You can specify what order the records are returned in any time you use a SELECT statement - just add an ORDER BY clause[^] and SQL will return rows ordered exactly the way you ask, and will return the same order records every time until you add, remove or change row data. But you can''t affect the order they are stored in, in the slightest.


刚想出来......

1.创建另一个像第一个表

2.使用INSERT INTO ... VALUES没有[idx],只有[col] ......

3. SELECT [col] FROM [db]。 [schm]。[table] ORDER BY [idx] DESC

4. INSERT INTO再次将第一行[col]追加到末尾(通知idx是完整的订单)

5.完成上述步骤,完全颠倒内容[idx]。
Just figured it out ...
1. Create another table like first table
2. Use INSERT INTO ... VALUES without [idx], just [col] ...
3. SELECT [col] FROM [db].[schm].[table] ORDER BY [idx] DESC
4. INSERT INTO again appending the "first row" [col] to the end (notice idx is intact order)
5. Do the whole above steps over reversing the contents [idx] wise.


这篇关于如何将数据前缀添加到表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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