在两行之间插入行 [英] Inserting Row in between two Rows

查看:97
本文介绍了在两行之间插入行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个记录的表(比如Table_A),以及从Table_A引用(外键)的另一个表(Say Table_B)。我想在Table_A的2个记录之间插入一条新记录。



每次插入新记录时,我都希望截断并插入Table_A和Table_B的所有记录。应该保留所有引用,因为它是新插入的记录在两个旧记录之间。



我导入Table_A和Excel工作表的记录,但Table_B数据是从fornt End。



先谢谢..

I have table(say Table_A) with 2 Records, and another table (Say Table_B) which is having reference (Foreign key) from Table_A. I Wanted to Insert a New Record in between 2 Records of Table_A.

Each time when I insert new records I wanted to truncate and insert all records of Table_A and Table_B which Should keep all references as it is with newly inserted record in between 2 old record.

I am importing records for Table_A and from Excel sheet, but Table_B data is inserting from fornt End.

Thanks in Advance..

推荐答案

SQL数据库中的行不像行在Excel中,它们在位置上彼此相关。不要想到数据库那种方式,正如ThePhantomUpvoter在评论中所说,排位无所谓。大多数(如果不是全部)SQL数据库没有在之间或之前插入行的方法,它们总是被追加。这是因为它必须更改数据库中的所有记录以更新/插入一个记录。这将是一项非常昂贵的操作。



为了按照您想要的顺序获取数据,请在SQL select语句中查找如何使用ORDER BY。根据您使用的数据库后端,您可以按照显示的顺序执行有趣的JOIN并形成您要查找的内容。
Rows in an SQL database are not like rows in Excel, where they are positionally related to each other. Don't think of a database that way, as ThePhantomUpvoter said in the comment, row position doesn't matter. Most (if not all) SQL databases don't have a method to insert rows between or before, they are always appended. This is because it would have to change all the records in the database to update/insert one. This would be a very expensive operation.

In order to get the data in the order you want, look up how to use ORDER BY in your SQL select statements. Depending on the database back-end you use, you can do interesting JOIN's and form what you are looking for in the order you need it displayed.


这篇关于在两行之间插入行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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