CN103678532B - Alternation statement reverse analysis method, database alternating and backspacing method and database alternating and backspacing system - Google Patents
Alternation statement reverse analysis method, database alternating and backspacing method and database alternating and backspacing system Download PDFInfo
- Publication number
- CN103678532B CN103678532B CN201310634777.9A CN201310634777A CN103678532B CN 103678532 B CN103678532 B CN 103678532B CN 201310634777 A CN201310634777 A CN 201310634777A CN 103678532 B CN103678532 B CN 103678532B
- Authority
- CN
- China
- Prior art keywords
- statement
- change
- rollback
- data
- database
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/25—Integrating or interfacing systems involving database management systems
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/21—Design, administration or maintenance of databases
- G06F16/217—Database tuning
Landscapes
- Engineering & Computer Science (AREA)
- Databases & Information Systems (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
一种变更语句逆向分析方法、数据库变更回退方法及系统,逆向分析方法包括:S1、确定变更语句涉及的对象、变更指令和对应于变更指令的回退指令;S2、如果变更语句进行创建/增加操作,则直接根据对象和回退指令确定回退语句;如果变更语句进行更改/删除操作,则确定被更改/删除的源数据/源内容,并根据对象、源数据/源内容和回退指令确定回退语句。回退方法包括:S10、获得SQL变更脚本输入、数据库版本和数据库授权;S20、对SQL变更脚本执行解析,生成语句解析结果;S30、基于语句解析结果,根据变更语句逆向分析方法生成回退语句并将回退语句转换为可执行的回退SQL脚本文件。该回退方法具有适用性广、可操作性强、安全、高效自动化的优点。
A change statement reverse analysis method, database change rollback method and system, the reverse analysis method includes: S1, determining the object involved in the change statement, the change instruction and the rollback instruction corresponding to the change instruction; S2, if the change statement is created/ Add operation, determine the rollback statement directly according to the object and the rollback instruction; if the change statement performs a change/delete operation, determine the changed/deleted source data/source content, and determine the changed/deleted source data/source content according to the object, source data/source content and rollback directive determines the fallback statement. The rollback method includes: S10, obtaining the input of the SQL change script, database version and database authorization; S20, performing analysis on the SQL change script, and generating a statement analysis result; S30, based on the statement analysis result, generating a rollback statement according to the reverse analysis method of the change statement And convert the rollback statement into an executable rollback SQL script file. The fallback method has the advantages of wide applicability, strong operability, safety, and high-efficiency automation.
Description
技术领域technical field
本发明涉及软件系统运维领域,尤其涉及一种变更语句逆向分析方法、数据库变更回退方法及系统。The invention relates to the field of software system operation and maintenance, in particular to a reverse analysis method for a change statement, a database change rollback method and a system.
背景技术Background technique
在软件生产系统运营过程中,随着业务的发展变化,常需要对软件系统进行功能改造或升级,改造和升级都会对软件系统本身带来变更。同时,在系统运行过程中,常会暴露出前期遗留的系统缺陷,对缺陷的修复也会导致系统变更。During the operation of the software production system, with the development and changes of the business, it is often necessary to modify or upgrade the functions of the software system, and the modification and upgrade will bring changes to the software system itself. At the same time, in the process of system operation, system defects left over from the previous period are often exposed, and the repair of defects will also lead to system changes.
在多数软件生产系统中,数据库系统是一个重要的组成部分。常见的数据库系统如Oracle、MySQL、Sybase、MS SQL server等,在各行各业的软件系统中得到了广泛的应用。因此,对软件系统的变更,多数情况下也会涉及数据库系统的变更。In most software production systems, the database system is an important component. Common database systems such as Oracle, MySQL, Sybase, MS SQL server, etc., have been widely used in software systems in various industries. Therefore, changes to the software system also involve changes to the database system in most cases.
系统部件根据存储形态,通常可分为文件和数据库。文件包含程序文件和配置文件,程序文件可能是二进制文件,也可能是文本格式的脚本文件,配置文件通常是ini、xml等格式的文本文件。文件的变更,一般是通过用新版本文件替换旧版本文件完成的。数据库的变更,通常包含数据定义变更、数据变更和权限变更。在进行数据库变更时,是通过执行相应的DDL(Data Definition Language,数据定义语言)、DML(Data ManipulationLanguage,数据操纵语言)、DCL(Data Control Language,数据控制语言)语句完成的。System components can usually be divided into files and databases according to the storage form. The file includes a program file and a configuration file. The program file may be a binary file or a script file in a text format. The configuration file is usually a text file in a format such as ini or xml. A file change is generally done by replacing an old version file with a new version file. Database changes usually include data definition changes, data changes, and permission changes. When the database is changed, it is completed by executing the corresponding DDL (Data Definition Language, Data Definition Language), DML (Data Manipulation Language, Data Manipulation Language), DCL (Data Control Language, Data Control Language) statement.
系统变更是必然的,但是因为一些原因,变更后的系统可能不会符合用户预期。常用的原因可能有,系统功能与用户需求不一致,变更引入了新的故障、变更无法完整实施。为了保证系统的正确性和可用性,某些情况下,需要对已完成的变更或未完成的变更实施回退,使系统恢复到变更前的状态。System changes are inevitable, but for some reasons, the changed system may not meet user expectations. Common reasons may be that system functions are not consistent with user requirements, changes introduce new faults, and changes cannot be fully implemented. In order to ensure the correctness and availability of the system, in some cases, it is necessary to roll back the completed or unfinished changes to restore the system to the state before the change.
同理,变更回退也包含文件回退和数据库回退。对文件的回退是通过将备份的旧版本文件覆盖新版本文件完成的。而对数据库的回退,通常有手工回退和整库备份恢复回退两种方式。Similarly, change rollback also includes file rollback and database rollback. The rollback of the files is done by overwriting the new version files with the backed up old version files. As for the rollback of the database, there are usually two methods: manual rollback and full database backup and recovery rollback.
手工回退指的是对每条变更语句进行逆向分析,然后执行对应的回退语句来达到数据库变更回退的目的。针对DDL和DCL语句,大部分数据库并无回退机制,只能手工完成回退;针对DML语句,因为变更执行后数据均已提交,一种方法是利用数据库机制如Oracle闪回机制实现回退,此方法有几个明显的局限性,一是适用条件苛刻,如Oracle闪回机制本身具有多种约束条件限制,且其它多数数据库并无类似的机制,二是可操作性不高,类似操作通常需要专门的数据库维护人员,三是类似回退方法会影响变更后到回退前这段时间内的其他数据变更,除非是变更完成后立即回退,所以通常还是利用手工方式完成DML回退。Manual rollback refers to the reverse analysis of each change statement, and then executes the corresponding rollback statement to achieve the purpose of database change rollback. For DDL and DCL statements, most databases do not have a rollback mechanism and can only be rolled back manually; for DML statements, because the data has been submitted after the change is executed, one method is to use the database mechanism such as the Oracle flashback mechanism to implement the rollback , this method has several obvious limitations. First, the applicable conditions are harsh. For example, the Oracle flashback mechanism itself has various constraints, and most other databases do not have similar mechanisms. Second, the operability is not high. Similar operations Usually, special database maintenance personnel are required. Third, similar rollback methods will affect other data changes during the period between the change and the rollback, unless the rollback is done immediately after the change is completed, so DML rollback is usually done manually. .
数据库手工回退方法,在数据库变更较小的情况下,是可以胜任回退任务的,但是又具备难以克服的缺陷。首先是人工成本高,因为需要人工核查每条数据库变更语句,然后编写对应的逆向语句,在变更比较大或比较频繁的情况下,需要花费大量的人力;其次是正确性无法保障,因为是通过人工来完成逆向,缺乏有效的核对机制来确保工作的正确性,变更较大的情况下极易出错;再次,手工回退需要确保变更涉及的表结构、数据和权限在变更前得到备份,否则无法进行回退;最后,操作效率低,针对大型的变更,人工操作效率不高,导致回退时间较长,因此会影响系统的可用性,导致其他一些间接的损失。The database manual rollback method is suitable for the rollback task when the database changes are small, but it has insurmountable defects. First of all, the labor cost is high, because it is necessary to manually check each database change statement, and then write the corresponding reverse statement. In the case of relatively large or frequent changes, it takes a lot of manpower; secondly, the correctness cannot be guaranteed, because through The reverse is done manually, and there is no effective checking mechanism to ensure the correctness of the work. In the case of large changes, it is very easy to make mistakes; again, manual rollback needs to ensure that the table structure, data and permissions involved in the change are backed up before the change, otherwise Unable to roll back; finally, the operation efficiency is low. For large-scale changes, the manual operation efficiency is not high, resulting in a long rollback time, which will affect the availability of the system and cause other indirect losses.
除了手工回退外,还可以通过整库备份恢复的方式进行变更回退,即在变更实施前对整个数据库进行备份,变更完成后如果需要回退,则使用变更前的数据库备份进行恢复。In addition to manual rollback, changes can also be rolled back through full database backup and recovery, that is, the entire database is backed up before the change is implemented. If rollback is required after the change is completed, the database backup before the change is used for recovery.
至于整库备份恢复回退方法,优点是能够完全恢复数据库,但也存在明显的缺陷。一是成本巨大,进行整库备份恢复通常需要停库,这对于某些系统是不可接受的,且如果变更较小,进行整库备份恢复会导致较多的资源和时间消耗;二是专业性强,整库备份恢复需要专门的数据库DBA来完成。As for the full database backup and recovery method, the advantage is that the database can be completely restored, but there are also obvious defects. First, the cost is huge. The backup and recovery of the whole database usually requires stopping the database, which is unacceptable for some systems, and if the changes are small, the backup and recovery of the whole database will lead to more resources and time consumption; the second is professionalism Strong, the entire database backup and recovery requires a dedicated database DBA to complete.
因此,目前对数据库变更的回退无论手工回退还是整库回退,都存在明显的缺陷。所以长远看来,需要有一种方案,能够解决手工回退和整库回退的缺陷,完成对数据库变更的自动化回退。Therefore, there are obvious defects in the current rollback of database changes, whether manual rollback or full database rollback. So in the long run, there needs to be a solution that can solve the defects of manual rollback and full database rollback, and complete the automatic rollback of database changes.
发明内容Contents of the invention
本发明要解决的技术问题在于,针对现有技术的上述手工回退存在的效率低、成本高、正确性无法保障的缺陷以及整库备存在的成本大、适用范围太窄的缺陷,提供一种适用性广、可操作性强、安全、高效自动化的变更语句逆向分析方法、数据库变更回退方法及系统。The technical problem to be solved by the present invention is to provide a solution for the defects of low efficiency, high cost, and unguaranteed correctness of the above-mentioned manual rollback in the prior art, as well as the high cost and narrow scope of application of the whole inventory. A reverse analysis method for a change statement, a database change rollback method and a system with wide applicability, strong operability, safety, high efficiency and automation.
本发明解决其技术问题所采用的技术方案是:构造一种变更语句逆向分析方法,用于数据库中在所述变更语句执行之前进行逆向分析生成回退语句,所述变更语句为SQL语句,所述方法包括以下步骤:The technical solution adopted by the present invention to solve the technical problem is: to construct a method for reverse analysis of the change statement, which is used in the database to perform reverse analysis before the execution of the change statement to generate a rollback statement. The change statement is an SQL statement, so Said method comprises the following steps:
S1、确定所述变更语句涉及的对象、变更指令和对应于所述变更指令的回退指令;S1. Determine the object involved in the change statement, the change instruction, and the rollback instruction corresponding to the change instruction;
S2、如果所述变更语句进行创建/增加操作,则直接根据所述对象和回退 指令确定回退语句;S2. If the change statement performs a create/add operation, then determine the rollback statement directly according to the object and the rollback instruction;
如果所述变更语句进行更改/删除操作,则确定被更改/删除的源数据/源内容,并根据所述对象、源数据/源内容和回退指令确定回退语句。If the change statement performs a change/deletion operation, determine the changed/deleted source data/source content, and determine a rollback statement according to the object, source data/source content, and rollback instruction.
本发明所述的变更语句逆向分析方法,其中,所述对象包括直接对象和与所述直接对象相关联的关联对象;In the method for reverse analysis of a change statement according to the present invention, the object includes a direct object and an associated object associated with the direct object;
所述步骤S1中,确定所述变更语句涉及的对象包括:根据所述变更语句直接获取所述直接对象;和根据所述变更语句通过查询数据字典间接获取所述关联对象;所述查询数据字典是通过查询语句查询数据库系统;In the step S1, determining the object involved in the change statement includes: directly obtaining the direct object according to the change statement; and indirectly obtaining the associated object by querying the data dictionary according to the change statement; the query data dictionary It is to query the database system through the query statement;
所述步骤S2中,确定被更改/删除的源数据/源内容包括:根据所述变更语句直接获取所述源数据/源内容;和根据所述变更语句通过查询数据表间接获取所述源数据/源内容;所述查询数据表是通过查询语句查询数据库系统和数据表。In the step S2, determining the changed/deleted source data/source content includes: directly obtaining the source data/source content according to the change statement; and indirectly obtaining the source data by querying a data table according to the change statement /source content; the query data table is to query the database system and data table through a query statement.
本发明所述的变更语句逆向分析方法,其中,所述变更语句包括DDL语句、DML语句和DCL语句;The method for reverse analysis of the change statement of the present invention, wherein the change statement includes a DDL statement, a DML statement and a DCL statement;
若变更语句为DDL语句,所述方法包括:创建对象的回退、更新对象的回退和删除对象的回退;If the change statement is a DDL statement, the method includes: the rollback of creating an object, the rollback of updating an object, and the rollback of deleting an object;
若变更语句为DML语句,所述方法包括:新增数据的回退,更新数据的回退,删除数据的回退;If the change statement is a DML statement, the method includes: the rollback of newly added data, the rollback of updated data, and the rollback of deleted data;
若变更语句为DCL语句,所述方法包括:授权语句的回退、权限回收语句的回退。If the change statement is a DCL statement, the method includes: rolling back the authorization statement and rolling back the permission recovery statement.
本发明所述的变更语句逆向分析方法,其中,如果变更语句为CREATEMM_name;其中M代表创建对象的类型,M_name代表创建对象的名称,所述创建对象的回退包括:In the method for reverse analysis of the change statement of the present invention, if the change statement is CREATEMM_name; wherein M represents the type of the created object, M_name represents the name of the created object, and the rollback of the created object includes:
S1a1、确定所述变更语句涉及的对象为M_name,变更指令为CREATE,CREATE对应的回退指令为DROP;S1a1. Determine that the object involved in the change statement is M_name, the change command is CREATE, and the rollback command corresponding to CREATE is DROP;
S2a1、所述变更语句仅进行创建操作,直接确定所述回退语句为:DROP M M_name;S2a1. The change statement only performs a creation operation, and directly determines that the rollback statement is: DROP M M_name;
如果变更语句为ALTER M M_name UD1,其中M代表更新对象的类型,M_name代表更新对象的名称,UD1代表更新内容的操作,UD1中涉及到的变更指令包括:ADD、DROP和MODIFY,所述更新对象的回退包括:If the change statement is ALTER M M_name UD1, where M represents the type of the object to be updated, M_name represents the name of the object to be updated, and UD1 represents the operation of updating the content, and the change instructions involved in UD1 include: ADD, DROP and MODIFY, the update object The fallbacks include:
S1a2、确定所述变更语句涉及的对象为M_name,变更指令包括:CREATE和UD1中涉及到的变更指令,CREATE对应的回退指令为DROP,ADD、DROP和MODIFY对应的回退指令分别为DROP、ADD和MODIFY;S1a2. Determine that the object involved in the change statement is M_name, and the change instructions include: the change instructions involved in CREATE and UD1, the rollback command corresponding to CREATE is DROP, and the rollback commands corresponding to ADD, DROP, and MODIFY are DROP, DROP, and MODIFY, respectively. ADD and MODIFY;
S2a2、所述变更语句进行更改操作,确定对应于UD1的被更改的源内容,确定所述回退语句为:ALTER M M_name UD2,UD2代表由对应于UD1的回退指令和源内容构成的实现回退的操作;S2a2. The change statement performs a change operation, determines the changed source content corresponding to UD1, and determines that the rollback statement is: ALTER M_name UD2, and UD2 represents the implementation composed of the rollback command corresponding to UD1 and the source content Rollback operation;
如果变更语句为DROP M M_name;其中M代表删除对象的类型,M_name代表删除对象的名称,所述删除对象的回退包括:If the change statement is DROP M M_name; where M represents the type of the object to be deleted, and M_name represents the name of the object to be deleted, the rollback of the deleted object includes:
S1a3、确定所述变更语句涉及的对象为M_name,变更指令为DROP,DROP对应的回退指令为CREATE;S1a3. Determine that the object involved in the change statement is M_name, the change command is DROP, and the fallback command corresponding to DROP is CREATE;
S2a3、所述变更语句进行删除操作,确定被删除的源内容,确定所述回退语句为:CREATE M M_name UD3,UD3代表由源内容构成的限定条件;S2a3. Perform a delete operation on the change statement, determine the deleted source content, and determine that the rollback statement is: CREATE M M_name UD3, where UD3 represents a limiting condition formed by the source content;
如果变更语句为INSERT INTO tb_a VALUES v_a,其中,tb_a代表新增数据的对象,v_a代表新增数据,所述新增数据的回退包括:If the change statement is INSERT INTO tb_a VALUES v_a, where tb_a represents the object of the newly added data, and v_a represents the newly added data, the rollback of the newly added data includes:
S1b1、确定所述变更语句涉及的对象为tb_a,变更指令为:INSERT,对应的回退指令为DELETE;S1b1. Determine that the object involved in the change statement is tb_a, the change command is: INSERT, and the corresponding rollback command is DELETE;
S2b1、所述变更语句进行更改操作,直接确定所述回退语句为:DELETE FROM M_name WHERE v_b,其中,v_b代表对应于新增数据v_a对应的字段;S2b1. Perform a change operation on the change statement, and directly determine that the rollback statement is: DELETE FROM M_name WHERE v_b, where v_b represents the field corresponding to the newly added data v_a;
如果变更语句为UPDATE tb_a SET c,其中,tb_a代表更新数据的对象,c代表更新数据的操作,所述更新数据的回退包括:If the change statement is UPDATE tb_a SET c, where tb_a represents the object of the updated data, and c represents the operation of updating the data, the rollback of the updated data includes:
S1b2、确定所述变更语句涉及的对象为tb_a,变更指令为UPDATE,UPDATE对应的回退指令为UPDATE;S1b2. Determine that the object involved in the change statement is tb_a, the change command is UPDATE, and the rollback command corresponding to UPDATE is UPDATE;
S2b2、所述变更语句进行更改操作,确定对应于c的源数据,确定所述回退语句为:UPDATE tb_a SET d WHERE e,其中,d代表源数据的具体数据,e代表源数据对应的字段;S2b2. The change statement performs a change operation, determines the source data corresponding to c, and determines that the rollback statement is: UPDATE tb_a SET d WHERE e, wherein, d represents the specific data of the source data, and e represents the field corresponding to the source data ;
如果变更语句为DELETE FROM tb_a WHERE c,其中,tb_a代表删除数据的对象,c代表删除数据对应的字段,所述删除数据的回退包括:If the change statement is DELETE FROM tb_a WHERE c, where tb_a represents the object of the deleted data, and c represents the field corresponding to the deleted data, the rollback of the deleted data includes:
S1b3、确定所述变更语句涉及的对象为tb_a,变更指令为:DELETE,DELETE对应的回退指令为INSERT;S1b3. Determine that the object involved in the change statement is tb_a, the change command is: DELETE, and the rollback command corresponding to DELETE is INSERT;
S2b3、所述变更语句进行删除操作,确定对应于c的源数据,确定所述回退语句为:INSERT INTO tb_a(col_a)VALUES d,其中,d代表源数据的具体数据,col_a代表源数据对应的字段;S2b3. The change statement performs a delete operation, determines the source data corresponding to c, and determines that the rollback statement is: INSERT INTO tb_a(col_a)VALUES d, wherein, d represents the specific data of the source data, and col_a represents the corresponding source data field;
如果变更语句为GRANT A USER TO user_a,所述授权语句的回退包括:If the change statement is GRANT A USER TO user_a, the fallback of the authorization statement includes:
S1c1、确定所述变更语句涉及的对象为user_a,变更指令为:GRANT,对应的回退指令为REVOKE;S1c1. Determine that the object involved in the change statement is user_a, the change command is: GRANT, and the corresponding rollback command is REVOKE;
S2c1、所述变更语句进行授权操作,直接确定所述回退语句为:REVOKE A FROMuser_a;S2c1. The change statement performs an authorization operation, and directly determines that the rollback statement is: REVOKE A FROMuser_a;
如果变更语句为REVOKE A ON tb_a FROM role_a;所述权限回收语句的回退包括:If the change statement is REVOKE A ON tb_a FROM role_a; the rollback of the permission recovery statement includes:
S1c1、确定所述变更语句涉及的对象为role_a,变更指令为:REVOKE,对应的回退指令为GRANT;S1c1. Determine that the object involved in the change statement is role_a, the change command is: REVOKE, and the corresponding rollback command is GRANT;
S2c1、所述变更语句进行权限回收操作,直接确定所述回退语句为:GRANT A ONtb_a TO role_a。S2c1. The change statement performs a permission recovery operation, and directly determines that the rollback statement is: GRANT A ONtb_a TO role_a.
本发明还公开了一种基于所述的变更语句逆向分析方法的数据库变更回退方法,所述方法包括以下步骤:The present invention also discloses a database change rollback method based on the reverse analysis method of the change statement, and the method includes the following steps:
S10、获得SQL变更脚本输入、数据库版本和数据库授权;S10, obtaining SQL change script input, database version and database authorization;
S20、对所述SQL变更脚本执行解析,生成语句解析结果;S20. Perform parsing on the SQL change script to generate a statement parsing result;
S30、基于所述语句解析结果,根据所述变更语句逆向分析方法生成回退语句并将所述回退语句转换为可执行的回退SQL脚本文件。S30. Based on the statement analysis result, generate a rollback statement according to the reverse analysis method for the change statement, and convert the rollback statement into an executable rollback SQL script file.
本发明所述的数据库变更回退方法,其中,所述方法还包括:In the database change rollback method described in the present invention, the method further includes:
S40、输入回退执行命令,运行所述回退SQL脚本文件实现数据库变更回退。S40. Input a rollback execution command, and run the rollback SQL script file to roll back the database change.
本发明所述的数据库变更回退方法,其中,所述步骤S10中,所述SQL变更脚本为包含所述变更语句的文本文件,所述数据库授权包括数据库用户名和密码;In the database change rollback method of the present invention, in the step S10, the SQL change script is a text file containing the change statement, and the database authorization includes a database user name and password;
所述步骤S20中执行解析为根据所述SQL变更脚本调用所述数据库版本的SQL引擎执行Flex词法分析和Bison语法分析。Performing the parsing in the step S20 is calling the SQL engine of the database version according to the SQL change script to perform Flex lexical analysis and Bison grammatical analysis.
本发明所述的数据库变更回退方法,其中,所述步骤S30中根据所述变更语句逆向分析方法生成的回退语句为由若干子句构成的逻辑回退语句,所述步骤S30将所述回退语句转换为可执行的回退SQL脚本文件具体包括:The database change rollback method according to the present invention, wherein the rollback statement generated according to the reverse analysis method of the change statement in the step S30 is a logical rollback statement composed of several clauses, and the step S30 combines the The conversion of rollback statements into executable rollback SQL script files specifically includes:
S31、重组:对所述子句进行重新组织;S31. Reorganization: reorganize the clauses;
S32、填充:将重组后的所述子句填充后形成完整且合法的SQL语句;S32. Filling: filling the reorganized clauses to form a complete and legal SQL statement;
S33、映射:将步骤S32中得到的具有不同实现的SQL语句映射为特定数据库系统的语句;S33. Mapping: mapping the SQL statements with different implementations obtained in step S32 into statements of a specific database system;
S34、合并:将数据导入命令和步骤S33中得到的语句合并为所述回退SQL脚本文件。S34. Merge: merge the data import command and the statement obtained in step S33 into the fallback SQL script file.
本发明还提供一种基于所述的数据库变更回退方法的数据库变更回退系统,所述系统包括:The present invention also provides a database change rollback system based on the database change rollback method, the system comprising:
用户接口层:用于与用户进行交互处理;所述交互处理包括获得SQL变更脚本输入、数据库版本、数据库授权以及回退执行命令;User interface layer: used for interactive processing with users; said interactive processing includes obtaining SQL change script input, database version, database authorization and rollback execution commands;
回退处理层:用于对所述SQL变更脚本执行解析,生成语句解析结果,并基于所述语句解析结果根据所述变更语句逆向分析方法生成回退语句,并将所述回退语句转换为可执行的回退SQL脚本文件;Rollback processing layer: used to analyze the SQL change script, generate a statement analysis result, and generate a rollback statement according to the reverse analysis method of the change statement based on the statement analysis result, and convert the rollback statement into Executable fallback SQL script file;
数据服务层:用于从数据库查询数据、进行源数据/源内容备份,以及在接收到所述回退执行命令时执行所述回退SQL脚本文件;Data service layer: for querying data from the database, backing up source data/source content, and executing the rollback SQL script file when receiving the rollback execution command;
数据库层:提供数据库系统。Database layer: Provides a database system.
本发明所述的数据库变更回退系统,其中,In the database change rollback system described in the present invention, wherein,
所述用户接口层的功能组件包括:The functional components of the user interface layer include:
命令处理组件:用于接收所述SQL变更脚本和回退执行命令;Command processing component: for receiving the SQL change script and rolling back the execution command;
信息交互组件:用于将所述数据库回退的过程与结果展示给用户;Information interaction component: used to display the process and results of the database rollback to the user;
所述回退处理层的功能组件包括:The functional components of the fallback processing layer include:
SQL引擎:根据数据库的词法和语法规则,完成SQL变更脚本的解析并生成语句解析结果,SQL变更脚本的解析包括词法分析和语法分析,所述词法分析采用Flex工具,所述语法分析采用Bison工具;SQL engine: according to the lexical and grammatical rules of the database, complete the parsing of the SQL change script and generate statement parsing results. The parsing of the SQL change script includes lexical analysis and grammatical analysis. The lexical analysis uses the Flex tool, and the grammatical analysis uses the Bison tool ;
脚本解析组件:用于根据数据库类型调用对应的所述SQL引擎完成SQL 变更脚本的解析;Script parsing component: used to call the corresponding SQL engine according to the database type to complete the parsing of the SQL change script;
逆向分析组件:用于分析所述语句解析结果,根据所述变更语句逆向分析方法生成回退语句;Reverse analysis component: used to analyze the statement analysis result, and generate a rollback statement according to the reverse analysis method of the change statement;
回退语句生成组件:用于结合所述数据服务层,将回退语句转换为和数据库类型相关的SQL回退语句,并将生成的回退SQL脚本文件提供给数据服务层;Rollback statement generation component: used to convert the rollback statement into a SQL rollback statement related to the database type in combination with the data service layer, and provide the generated rollback SQL script file to the data service layer;
所述数据服务层包括:The data service layer includes:
数据查询组件:用于从数据库获得所述SQL回退语句并生成需要的数据;Data query component: used to obtain the SQL rollback statement from the database and generate required data;
数据备份组件:用于对回退需要备份的源数据/源内容进行备份和管理;Data backup component: used to back up and manage the source data/source content that needs to be backed up during rollback;
脚本执行组件:用于获取所述回退SQL脚本文件,完成回退SQL脚本文件的执行;Script execution component: used to obtain the rollback SQL script file, and complete the execution of the rollback SQL script file;
所述数据库层包括:Oracle、MySQL、Sybase、SQL Server系统。The database layer includes: Oracle, MySQL, Sybase, SQL Server systems.
实施本发明的变更语句逆向分析方法、数据库变更回退方法及系统,具有以下有益效果:本发明的变更语句逆向分析方法在所述变更语句执行之前进行逆向分析生成回退语句,回退语句仅仅对变更语句涉及的对象或者对象的源数据/源内容进行回退,针对性强,工作量小。数据库变更回退方法利用该方法生成的回退语句,转换为可执行的回退SQL脚本文件,在需要进行数据库的回退时,执行回退SQL脚本文件即可,达到了适用性广、可操作性强、安全、高效自动化的优点。Implementing the reverse analysis method for change statement, database change rollback method and system of the present invention has the following beneficial effects: the reverse analysis method for change statement of the present invention performs reverse analysis before the execution of the change statement to generate a rollback statement, and the rollback statement only Roll back the object involved in the change statement or the source data/source content of the object, with strong pertinence and small workload. The database change rollback method uses the rollback statement generated by this method to convert it into an executable rollback SQL script file. When it is necessary to roll back the database, just execute the rollback SQL script file, achieving wide applicability and reliability. The advantages of strong operability, safety, and high-efficiency automation.
附图说明Description of drawings
下面将结合附图及实施例对本发明作进一步说明,附图中:The present invention will be further described below in conjunction with accompanying drawing and embodiment, in the accompanying drawing:
图1是本发明变更语句逆向分析方法的流程图;Fig. 1 is the flow chart of the reverse analysis method of change sentence of the present invention;
图2A是本发明数据库变更回退方法的第一实施例的流程图;FIG. 2A is a flow chart of the first embodiment of the database change rollback method of the present invention;
图2B是本发明数据库变更回退方法的第二实施例的流程图;FIG. 2B is a flow chart of the second embodiment of the database change rollback method of the present invention;
图3是本发明数据库变更回退方法中INSERT语句语法解析的最终语法树;Fig. 3 is the final syntax tree of the INSERT statement syntax analysis in the database change rollback method of the present invention;
图4是本发明数据库变更回退系统的架构层次图;FIG. 4 is a hierarchical diagram of the structure of the database change rollback system of the present invention;
图5是本发明数据库变更回退系统的系统组件图。Fig. 5 is a system component diagram of the database change rollback system of the present invention.
具体实施方式detailed description
为了对本发明的技术特征、目的和效果有更加清楚的理解,现对照附图详细说明本发明的具体实施方式。In order to have a clearer understanding of the technical features, purposes and effects of the present invention, the specific implementation manners of the present invention will now be described in detail with reference to the accompanying drawings.
参考图1是本发明变更语句逆向分析方法的流程图;Referring to Fig. 1, it is a flow chart of the reverse analysis method for changing sentences of the present invention;
本发明的变更语句逆向分析方法,用于数据库中在变更语句执行之前进行逆向分析生成回退语句,所述变更语句为SQL语句,方法包括以下步骤:The reverse analysis method of the change statement of the present invention is used in the database to carry out reverse analysis before the execution of the change statement to generate a rollback statement, the change statement is an SQL statement, and the method includes the following steps:
S1、确定变更语句涉及的对象、变更指令和对应于变更指令的回退指令;S1. Determine the objects involved in the change statement, the change instruction and the rollback instruction corresponding to the change instruction;
其中,对象包括直接对象和与直接对象相关联的关联对象,确定变更语句涉及的对象包括:根据变更语句直接获取直接对象;和根据变更语句通过查询数据字典间接获取关联对象;Wherein, the object includes a direct object and an associated object associated with the direct object, and determining the object involved in the change statement includes: directly obtaining the direct object according to the change statement; and indirectly obtaining the associated object by querying the data dictionary according to the change statement;
S2、如果变更语句进行创建/增加操作,则直接根据对象和回退指令确定回退语句;如果变更语句进行更改/删除操作,则确定被更改/删除的源数据/源内容,并根据对象、源数据/源内容和回退指令确定回退语句;S2. If the change statement performs a create/add operation, determine the rollback statement directly according to the object and the rollback instruction; if the change statement performs a change/delete operation, determine the changed/deleted source data/source content, and determine the changed/deleted source data/source content according to the object, The source data/source content and fallback instructions determine the fallback statement;
确定被更改/删除的源数据/源内容包括:根据变更语句直接获取源数据/源内容;和根据变更语句通过查询数据表间接获取源数据/源内容。其中,源内容包括对象的详细属性以及与对象相关的数据和状态;Determining the changed/deleted source data/source content includes: directly obtaining the source data/source content according to the change statement; and indirectly obtaining the source data/source content by querying the data table according to the change statement. Among them, the source content includes the detailed properties of the object and the data and status related to the object;
查询数据字典是指通过查询语句查询数据库系统,查询数据表是指通过查询语句查询数据库系统和数据表。Querying the data dictionary refers to querying the database system through query statements, and querying data tables refers to querying the database system and data tables through query statements.
本发明主要针对三类变更语句:DDL语句、DML语句和DCL语句:The present invention is mainly aimed at three types of change statements: DDL statement, DML statement and DCL statement:
DDL是数据定义语言,主要用于定义、更新、删除数据库对象,通常的数据库对象包含表、视图、索引、约束、存储过程、触发器、角色、用户等;DML是数据操纵语言,用于操作数据库中的数据。通常是对数据的查询、插入、更新、删除;DCL是数据控制语言,用于系统角色控制和授权,通常是对用户和角色权限的授权和取消授权。DDL is a data definition language, which is mainly used to define, update, and delete database objects. Common database objects include tables, views, indexes, constraints, stored procedures, triggers, roles, users, etc.; DML is a data manipulation language, used to operate data in the database. Usually it is the query, insertion, update, and deletion of data; DCL is a data control language, which is used for system role control and authorization, usually authorization and deauthorization of user and role permissions.
若变更语句为DDL语句,方法包括:创建对象的回退、更新对象的回退和删除对象的回退;If the change statement is a DDL statement, the method includes: rollback of creating an object, rollback of updating an object, and rollback of deleting an object;
若变更语句为DML语句,方法包括:新增数据的回退,更新数据的回退,删除数据的回退,MERGE类数据变更语句的回退,具有复杂变更条件的数据变更语句的回退,可包含重复行的表数据变更的回退;If the change statement is a DML statement, the methods include: rollback of new data, rollback of updated data, rollback of deleted data, rollback of MERGE data change statements, rollback of data change statements with complex change conditions, Rollback of table data changes that can contain duplicate rows;
若变更语句为DCL语句,方法包括:授权语句的回退、权限回收语句的回退。下面结合具体的例子介绍以上三类变更语句的逆向分析方法。If the change statement is a DCL statement, the method includes: rolling back the authorization statement, and rolling back the permission recovery statement. The reverse analysis method of the above three types of change statements is introduced below with specific examples.
(a1)创建对象的回退(a1) Fallback for object creation
变更语句创建了数据库对象,在变更前,数据库并不存在这个对象,回退比较简单,删除创建的数据库对象即可:The change statement creates a database object. Before the change, this object does not exist in the database. The rollback is relatively simple, just delete the created database object:
如果变更语句为CREATE M M_name;其中M代表创建对象的类型,M_name代表创建对象的名称,创建对象的回退包括:If the change statement is CREATE M M_name; where M represents the type of the object to be created, and M_name represents the name of the object to be created, the rollback of the object creation includes:
S1a1、确定变更语句涉及的对象为M_name,变更指令为CREATE,CREATE对应的回退指令为DROP;S1a1. Determine that the object involved in the change statement is M_name, the change command is CREATE, and the rollback command corresponding to CREATE is DROP;
S2a1、变更语句仅进行创建操作,直接确定回退语句为:DROP M M_name;S2a1. The change statement only performs the creation operation, and directly determines the rollback statement as: DROP M M_name;
例如:E.g:
a1-1)变更语句:CREATE TABLE tb_a;a1-1) Change statement: CREATE TABLE tb_a;
分析:涉及的对象为直接对象tb_a,变更指令为CREATE,则回退指令为DROP。Analysis: The object involved is the direct object tb_a, the change command is CREATE, and the rollback command is DROP.
对应的回退语句:DROP TABLE tb_a;Corresponding rollback statement: DROP TABLE tb_a;
a1-2)变更语句:CREATE INDEX idx_a;a1-2) Change statement: CREATE INDEX idx_a;
分析:涉及的对象为直接对象idx_a,变更指令为CREATE,则回退指令为DROP。Analysis: The object involved is the direct object idx_a, the change command is CREATE, and the rollback command is DROP.
对应的回退语句:DROP INDEX idx_a;Corresponding rollback statement: DROP INDEX idx_a;
(a2)更新对象的回退(a2) Fallback for updating objects
更新对象的回退对更新的对象进行了更改,所以需要备份被更改的源内容:例如更前数据库对象的详细属性。因为对象更新可能会涉及到与该对象相关的关联对象的变化,例如数据约束条件的变化,因为数据约束,可能导致回退不成功,在这种情况下,源内容还包括与对象相关的原来的数据。在备份源内容的数据时,如果涉及到某些行或者列,则可只备份具体的行和列,否则可能需要全表备份。The rollback of the updated object changes the updated object, so it is necessary to back up the changed source content: for example, the detailed attributes of the previous database object. Because the object update may involve the change of the associated object related to the object, such as the change of the data constraint condition, because of the data constraint, it may cause the rollback to be unsuccessful. In this case, the source content also includes the original content related to the object The data. When backing up the data of the source content, if certain rows or columns are involved, only specific rows and columns can be backed up; otherwise, a full table backup may be required.
如果变更语句为ALTER M M_name UD1,其中M代表更新对象的类型,M_name代表更新对象的名称,UD1代表更新内容的操作,UD1中涉及到的变更指令包括:ADD、DROP和MODIFY,更新对象的回退包括:If the change statement is ALTER M M_name UD1, where M represents the type of the object to be updated, M_name represents the name of the object to be updated, and UD1 represents the operation of updating the content. The change commands involved in UD1 include: ADD, DROP, and MODIFY. Refund includes:
S1a2、确定变更语句涉及的对象为M_name,变更指令包括:CREATE和UD1中涉及到的变更指令,CREATE对应的回退指令为DROP,ADD、DROP和MODIFY对应的回退指令分别为DROP、ADD和MODIFY;S1a2. Determine that the object involved in the change statement is M_name, and the change instructions include: the change instructions involved in CREATE and UD1, the rollback command corresponding to CREATE is DROP, and the rollback commands corresponding to ADD, DROP, and MODIFY are DROP, ADD, and MODIFY;
S2a2、变更语句进行更改操作,确定对应于UD1的被更改的源内容,确定 回退语句为:ALTER M M_name UD2,UD2代表由对应于UD1的回退指令和源内容构成的实现回退的操作;S2a2. Change the statement to perform the change operation, determine the changed source content corresponding to UD1, and determine the rollback statement as: ALTER M_name UD2, UD2 represents the rollback operation composed of the rollback instruction corresponding to UD1 and the source content ;
例如:E.g:
a2-1)变更语句:ALTER TABLE tb_a ADD col_a INTEGER NOT NULL;a2-1) Change statement: ALTER TABLE tb_a ADD col_a INTEGER NOT NULL;
分析:涉及的对象为直接对象tb_a,变更指令为ALTER和ADD,则回退指令为ALTER和DROP,之前不存在col_a,因此,回退时需要删除该列。Analysis: The object involved is the direct object tb_a, the change command is ALTER and ADD, and the rollback command is ALTER and DROP, and col_a did not exist before, so this column needs to be deleted when rolling back.
对应的回退语句:ALTER TABLE tb_a DROP COLUMN col_a;Corresponding rollback statement: ALTER TABLE tb_a DROP COLUMN col_a;
a2-2)变更语句:ALTER TABLE tb_a MODIFY col_a VARCHAR2(32)DEFAULT‘TEST’NOT NULL;a2-2) Change statement: ALTER TABLE tb_a MODIFY col_a VARCHAR2(32) DEFAULT ‘TEST’ NOT NULL;
分析:涉及的对象为tb_a,变更指令为ALTER和MODIFY,则回退指令为ALTER和MODIFY,被更改的源内容为col_a列的属性:数据类型、缺省值和字段是否非空。变更将数据表tb_a的列col_a类型修改为VARCHAR232,缺省值为字符串‘TEST’,字段非空,在变更语句中并不知道变更前列col_a的数据类型,因此需要先获得变更前列col_a的数据类型,通过如下查询语句查询数据表:Analysis: The object involved is tb_a, the change command is ALTER and MODIFY, then the rollback command is ALTER and MODIFY, and the changed source content is the attributes of col_a column: data type, default value and whether the field is not empty. Change the type of column col_a in the data table tb_a to VARCHAR232, the default value is the string 'TEST', and the field is not empty. In the change statement, the data type of the column col_a before the change is not known, so the data of the column col_a before the change needs to be obtained first Type, query the data table through the following query statement:
SELECT data_type,data_length,nullable,nvl2(data_default,’N’,’Y’)default_exist FROM user_tab_columns WHERE table_name=UPPER('tb_a')and column_name=upper('col_a');SELECT data_type, data_length, nullable, nvl2(data_default, 'N', 'Y') default_exist FROM user_tab_columns WHERE table_name=UPPER('tb_a')and column_name=upper('col_a');
假设如上语句获取到的结果为:VARCHAR2,16,‘N’,’Y’,则表示列col_a原来的数据类型为VARCHAR2,长度为16,是非空字段,且存在缺省值,那么还需要获取其原来的缺省值,可通过如下语句获取:Assuming that the result obtained by the above statement is: VARCHAR2, 16, 'N', 'Y', it means that the original data type of column col_a is VARCHAR2, the length is 16, it is a non-null field, and there is a default value, then you need to obtain Its original default value can be obtained through the following statement:
假设如上语句输出结果为:‘ABC’,表示该字段原来缺省值为字符串‘ABC’。Assuming that the output of the above statement is: 'ABC', it means that the original default value of this field is the string 'ABC'.
此处还需注意,因为此变更语句修改了字段长度,因此在变更后插入的列值可能会使用新的长度,而在数据库回退过程中,通常不能从较长的长度回退到较短的长度,所以此处的源内容还包括原来的字段值。假设此处通过SQL形式备份到SQL文件import_data_tb_a.sql。It should also be noted here that because this change statement modifies the field length, the column value inserted after the change may use the new length, and during the database rollback process, it is usually not possible to roll back from a longer length to a shorter one. length, so the source content here also includes the original field value. Assume that the SQL file is backed up to import_data_tb_a.sql here.
对应的回退语句:The corresponding fallback statement:
UPDATE tb_a SET col_a=‘’;UPDATE tb_a SET col_a='';
ALTER TABLE tb_a MODIFY col_a VARCHAR2(16)DEFAULT‘ABC’NOT NULL;ALTER TABLE tb_a MODIFY col_a VARCHAR2(16) DEFAULT 'ABC' NOT NULL;
再执行import_data_tb_a.sql导入数据。Then execute import_data_tb_a.sql to import data.
(a3)删除对象的回退(a3) Fallback for deleting objects
对于不涉及数据和状态的对象,如索引,视图、用户、角色、存储过程、触发器、函数等,源内容即为这些数据库对象的详细属性。对于和数据或状态相关的数据库对象,如表、字段、序列等,源内容不但包括对象属性,还包括与对象相关的数据或对象的状态。如变更语句删除了一个数据表,那么在回退 时,不但需要获得原来的表结构,还需要获得原来的表数据;如变更语句删除了一个序列,那么在回退时,不但要获得序列的初始、步长、最大值等属性,还要获得序列的状态即当前值。For objects that do not involve data and state, such as indexes, views, users, roles, stored procedures, triggers, functions, etc., the source content is the detailed properties of these database objects. For database objects related to data or state, such as tables, fields, sequences, etc., the source content includes not only object attributes, but also object-related data or object states. If a change statement deletes a data table, then when rolling back, not only the original table structure but also the original table data need to be obtained; if a change statement deletes a sequence, then when rolling back, not only the original table structure must be obtained Attributes such as initial, step size, maximum value, etc., also obtain the state of the sequence, that is, the current value.
删除表可能会对与该表相关联的关联对象产生影响,如删除表对象将会同时删除掉表上的索引、主键、约束、触发器,与该数据表相关的存储过程会失效。因此源内容还包括:关联对象的属性,以便回退时重建和重新生效。Deleting a table may affect the associated objects associated with the table. For example, deleting a table object will delete the indexes, primary keys, constraints, and triggers on the table at the same time, and the stored procedures related to the data table will become invalid. Therefore, the source content also includes: the attributes of the associated object, so that it can be reconstructed and revalidated when it is rolled back.
如果变更语句为DROP M M_name;其中M代表删除对象的类型,M_name代表删除对象的名称,删除对象的回退包括:If the change statement is DROP M M_name; where M represents the type of the object to be deleted, and M_name represents the name of the object to be deleted, the fallback of the deleted object includes:
S1a3、确定变更语句涉及的对象为M_name,变更指令为DROP,DROP对应的回退指令为CREATE;S1a3. Determine that the object involved in the change statement is M_name, the change command is DROP, and the fallback command corresponding to DROP is CREATE;
S2a3、变更语句进行删除操作,确定被删除的源内容,确定回退语句为:CREATE MM_name UD3,UD3代表由源内容构成的限定条件;S2a3. Change the statement to perform the delete operation, determine the source content to be deleted, and determine the rollback statement as: CREATE MM_name UD3, where UD3 represents the limiting condition formed by the source content;
例如:E.g:
a3-1)变更语句:DROP INDEX idx_a;a3-1) Change statement: DROP INDEX idx_a;
分析:涉及的对象为直接对象idx_a,变更指令为DROP,则回退指令为CREATE,变更语句删除了索引idx_a,回退时首先需要获得索引的特征,因此源内容包括:表名、用户名、是否唯一索引,可通过如下查询语句获得:Analysis: The object involved is the direct object idx_a, the change command is DROP, the rollback command is CREATE, the change statement deletes the index idx_a, and the feature of the index needs to be obtained first when rolling back, so the source content includes: table name, user name, Whether it is a unique index can be obtained through the following query statement:
SELECT index_name,uniqueness,table_name,table_owner FROM user_indexesWHERE index_name='idx_a';SELECT index_name, uniqueness, table_name, table_owner FROM user_indexes WHERE index_name='idx_a';
假设如上语句查询结果为:’idx_a’,’UNIQUE’,’tb_a’,’user_a’,则表示索引idx_a为唯一索引,建立在表tb_a上,所属用户为user_a。Assuming that the query result of the above statement is: 'idx_a', 'UNIQUE', 'tb_a', 'user_a', it means that the index idx_a is a unique index, built on the table tb_a, and belongs to the user user_a.
源内容还包含其索引的列及顺序,可通过如下查询语句获得:The source content also includes the columns and order of its index, which can be obtained through the following query statement:
SELECT column_name,descend FROM user_ind_columns WHERE index_name ='idx_a'order by column_position;SELECT column_name,descend FROM user_ind_columns WHERE index_name ='idx_a'order by column_position;
假设如上语句查询结果为:Suppose the query result of the above statement is:
col_a,ASCcol_a,ASC
col_b,DESCcol_b, DESC
表明索引idx_a包含两列,第一列为col_a,升序,第二列为col_b,降序。Indicates that the index idx_a contains two columns, the first column is col_a, in ascending order, and the second column is col_b, in descending order.
对应的回退语句:The corresponding fallback statement:
CREATE UNIQUE INDEX idx_a ON tb_a(col_a ASC,col_b DESC);CREATE UNIQUE INDEX idx_a ON tb_a(col_a ASC, col_b DESC);
a3-2)变更语句:DROP TABLE tb_a;a3-2) Change statement: DROP TABLE tb_a;
分析:涉及的对象为直接对象tb_a以及与该表关联的关联对象:主键、索引、外键、约束、触发器等,变更指令为DROP,则回退指令为CREATE,源内容包括表的所有行和列以及表里的数据以及所有对象的详细属性,因此如果要回退,需要重建所有对象,并重新导入数据。Analysis: The objects involved are the direct object tb_a and the associated objects associated with the table: primary key, index, foreign key, constraint, trigger, etc., the change command is DROP, the rollback command is CREATE, and the source content includes all rows of the table And the data in columns and tables and the detailed properties of all objects, so if you want to roll back, you need to rebuild all objects and re-import the data.
首先获得表所有列及其属性,以便查询数据及重建表,可通过如下语句:First get all the columns and their attributes of the table, in order to query data and rebuild the table, you can use the following statement:
SELECTt.column_name,t.data_type,t.data_length,t.data_precision,t.data_scale,t.nullable,t.data_default,c.commentsSELECT t.column_name, t.data_type, t.data_length, t.data_precision, t.data_scale, t.nullable, t.data_default, c.comments
FROM user_tab_columns t,user_col_comments c WHERE t.table_name=c.table_name AND t.column_name=c.column_name AND t.table_name='TB_A';FROM user_tab_columns t, user_col_comments c WHERE t.table_name=c.table_name AND t.column_name=c.column_name AND t.table_name='TB_A';
根据列名导出数据,对tb_a表来说,执行如下语句备份数据到import_data_tb_a.sql文件里:Export data according to the column name. For the tb_a table, execute the following statement to back up the data to the import_data_tb_a.sql file:
SELECT col_a,col_b,col_c FROM tb_a;SELECT col_a, col_b, col_c FROM tb_a;
查询表的主键及构成列,以便重建主键,通过如下语句:Query the primary key and constituent columns of the table in order to rebuild the primary key through the following statement:
SELECT t.constraint_name,c.column_name,c.position FROM user_constraints t,user_cons_columns c WHERE t.constraint_name=c.constraint_nameAND t.constraint_type='P'AND t.table_name='TB_A';SELECT t.constraint_name,c.column_name,c.position FROM user_constraints t,user_cons_columns c WHERE t.constraint_name=c.constraint_name AND t.constraint_type='P'AND t.table_name='TB_A';
查询表的索引及构成列,以便重建索引,通过如下语句:Query the index and constituent columns of the table in order to rebuild the index, through the following statement:
SELECT i.index_name,c.column_name,c.column_position,c.descend FROMuser_indexes i,user_ind_columns c WHERE i.index_name=c.index_name ANDi.table_name='TB_A';SELECT i.index_name,c.column_name,c.column_position,c.descend FROMuser_indexes i,user_ind_columns c WHERE i.index_name=c.index_name ANDi.table_name='TB_A';
查询表的唯一性约束和外键及构成列,以便重建约束和外键,通过如下语句:Query the unique constraints, foreign keys and constituent columns of the table, so as to rebuild the constraints and foreign keys, through the following statement:
SELECT t.constraint_name,c.column_name,c.position FROM user_constraints t,user_cons_columns c WHERE t.constraint_name=c.constraint_nameAND t.constraint_type IN('U','R')AND t.table_name='TB_A';SELECT t.constraint_name,c.column_name,c.position FROM user_constraints t,user_cons_columns c WHERE t.constraint_name=c.constraint_nameAND t.constraint_type IN('U','R')AND t.table_name='TB_A';
查询表的触发器及代码,以便重建触发器,通过如下语句:Query the trigger and code of the table, so as to rebuild the trigger, pass the following statement:
SELECT t.trigger_name,t.trigger_type,s.line,s.text FROM user_triggerst,user_source s WHERE t.trigger_name=s.name AND t.table_name='TB_A';SELECT t.trigger_name,t.trigger_type,s.line,s.text FROM user_triggerst,user_sources WHERE t.trigger_name=s.name AND t.table_name='TB_A';
对应的回退语句:通过上述分析结果,重新构建创建表语句,创建主键、索引、外键、约束、触发器语句,创建成功后,导入备份的数据,具体的创建语句为本领域公知技术,此处不再赘述。Corresponding rollback statement: Based on the above analysis results, rebuild the table creation statement, create the primary key, index, foreign key, constraint, and trigger statement. After the creation is successful, import the backup data. The specific creation statement is a well-known technology in the art. I won't repeat them here.
(b1)新增数据的回退(b1) Rollback of new data
如果变更语句为INSERT INTO tb_a VALUES v_a,其中,tb_a代表新增 数据的对象,v_a代表新增数据,新增数据的回退包括:If the change statement is INSERT INTO tb_a VALUES v_a, where tb_a represents the object of the new data, and v_a represents the new data, the rollback of the new data includes:
S1b1、确定变更语句涉及的对象为tb_a,变更指令为:INSERT,对应的回退指令为DELETE;S1b1. Determine that the object involved in the change statement is tb_a, the change command is: INSERT, and the corresponding rollback command is DELETE;
S2b1、变更语句进行更改操作,直接确定回退语句为:DELETE FROM M_name WHEREv_b,其中,v_b代表对应于新增数据v_a对应的字段;S2b1. Change the statement to perform the change operation, and directly determine the rollback statement as: DELETE FROM M_name WHEREv_b, where v_b represents the field corresponding to the newly added data v_a;
例如:E.g:
b1-1)变更语句:INSERT INTO tb_a(col_a,col_b)VALUES(1,’v_a’);b1-1) Change statement: INSERT INTO tb_a(col_a,col_b)VALUES(1,'v_a');
分析:涉及的对象为直接对象tb_a,变更指令为INSERT,则回退指令为DELETE,新增数据(1,’v_a’)对应的字段为:col_a=1AND col_b=‘v-a’。Analysis: The object involved is the direct object tb_a, the change command is INSERT, the rollback command is DELETE, and the field corresponding to the new data (1,'v_a') is: col_a=1AND col_b='v-a'.
对应的回退语句:DELETE FROM tb_a WHERE col_a=1AND col_b=‘v-a’;Corresponding fallback statement: DELETE FROM tb_a WHERE col_a=1AND col_b=‘v-a’;
b1-2)变更语句:INSERT INTO tb_a VALUES(1,’v_a’,v_b’);b1-2) Change statement: INSERT INTO tb_a VALUES(1,'v_a',v_b');
分析:涉及的对象为直接对象tb_a,变更指令为INSERT,则回退指令为DELETE,为了确定新增数据对应的字段,需要获取表的所有列名,可通过如下查询语句获取:Analysis: The object involved is the direct object tb_a, the change command is INSERT, and the rollback command is DELETE. In order to determine the fields corresponding to the newly added data, it is necessary to obtain all the column names of the table, which can be obtained through the following query statement:
SELECT column_name FROM user_tab_columns WHERE table_name='tb_a'ORDERBY column_id;SELECT column_name FROM user_tab_columns WHERE table_name='tb_a' ORDER BY column_id;
假设如上语句查询结果为:Suppose the query result of the above statement is:
col_acol_a
col_bcol_b
col_ccol_c
则表明数据表tb_a的列按顺序分别为col_a,col_b,col_c。It indicates that the columns of the data table tb_a are col_a, col_b, and col_c in order.
对应的回退语句:DELETE FROM tb_a WHERE col_a=1AND col_b=‘v_a’AND col_c=‘v_b’;Corresponding rollback statement: DELETE FROM tb_a WHERE col_a=1AND col_b='v_a'AND col_c='v_b';
(b2)更新数据的回退(b2) Rollback of updated data
如果变更语句为UPDATE tb_a SET c,其中,tb_a代表更新数据的对象,c代表更新数据的操作,更新数据的回退包括:If the change statement is UPDATE tb_a SET c, where tb_a represents the object of the updated data, and c represents the operation of updating the data, the rollback of the updated data includes:
S1b2、确定变更语句涉及的对象为tb_a,变更指令为UPDATE,UPDATE对应的回退指令为UPDATE;S1b2. Determine that the object involved in the change statement is tb_a, the change command is UPDATE, and the rollback command corresponding to UPDATE is UPDATE;
S2b2、变更语句进行更改操作,确定对应于c的源数据,确定回退语句为:UPDATEtb_a SET d WHERE e,其中,d代表源数据的具体数据,e代表源数据对应的字段;S2b2. Change the statement to perform a change operation, determine the source data corresponding to c, and determine the rollback statement as: UPDATEtb_a SET d WHERE e, where d represents the specific data of the source data, and e represents the field corresponding to the source data;
UPDATE语句更新了数据表的数据,要进行回退操作,首先需分析是否可以从变更语句推导出回退语句,如不能,则必须要备份更新前的数据。如下两个实例分别说明不可推导和可推导出回退语句的分析机制。The UPDATE statement updates the data in the data table. To perform a rollback operation, it is first necessary to analyze whether the rollback statement can be deduced from the change statement. If not, the data before the update must be backed up. The following two examples respectively illustrate the analysis mechanism of non-derivable and derivable fallback statements.
例如:E.g:
b2-1)变更语句:UPDATE tb_a SET col_c=10;b2-1) Change statement: UPDATE tb_a SET col_c=10;
分析:涉及的对象为tb_a,变更指令为UPDATE,则回退指令为UPDATE,变更语句更新了表tb_a所有行的字段col_c值为10,因此源数据为col_c中的数据。对于有主键的数据表,只需备份主键字段和变更字段的值;对于无主键的数据表,可通过备份系统行标识如Oracle ROWID和变更字段,或进行全表备份。查询表是否存在主键可通过如下语句完成:Analysis: The object involved is tb_a, the change command is UPDATE, then the rollback command is UPDATE, the change statement updates the field col_c value of all rows in table tb_a to 10, so the source data is the data in col_c. For a data table with a primary key, you only need to back up the primary key field and the value of the changed field; for a data table without a primary key, you can back up system row identifiers such as Oracle ROWID and changed fields, or perform a full table backup. Querying whether a table has a primary key can be done through the following statement:
SELECT constraint_name FROM user_constraints WHERE table_name='tb_a'AND constraint_type='P';SELECT constraint_name FROM user_constraints WHERE table_name='tb_a'AND constraint_type='P';
假设如上语句查询结果为:SYS_C0000001,则表示数据表tb_a存在名为SYS_C0000001的主键,继续查询主键字段,通过如下语句:Assuming that the query result of the above statement is: SYS_C0000001, it means that there is a primary key named SYS_C0000001 in the data table tb_a, continue to query the primary key field, and use the following statement:
SELECT column_name FROM user_cons_columns WHERE constraint_name= 'SYS_C0000001';SELECT column_name FROM user_cons_columns WHERE constraint_name= 'SYS_C0000001';
假设如上语句查询结果为:Suppose the query result of the above statement is:
col_acol_a
col_bcol_b
表明数据表tb_a的主键字段为col_a,col_b,那么我们备份数据只需要备份col_a,col_b,col_c的值,通过如下语句查询数据表tb_a:It indicates that the primary key fields of the data table tb_a are col_a, col_b, then we only need to back up the values of col_a, col_b, and col_c to back up the data, and query the data table tb_a through the following statement:
SELECT col_a,col_b,col_c FROM tb_a;SELECT col_a, col_b, col_c FROM tb_a;
假设查询结果为:Suppose the query result is:
1,10,1001,10,100
2,20,2002,20,200
3,30,3003,30,300
对应的回退语句:The corresponding fallback statement:
UPDATE tb_a SET col_c=100WHERE col_a=1AND col_b=10;UPDATE tb_a SET col_c=100WHERE col_a=1AND col_b=10;
UPDATE tb_a SET col_c=200WHERE col_a=2AND col_b=20;UPDATE tb_a SET col_c=200WHERE col_a=2AND col_b=20;
UPDATE tb_a SET col_c=300WHERE col_a=3AND col_b=30;UPDATE tb_a SET col_c=300WHERE col_a=3AND col_b=30;
b2-2)变更语句:UPDATE tb_a SET col_b=col_b+100WHERE col_b=10;b2-2) Change statement: UPDATE tb_a SET col_b=col_b+100WHERE col_b=10;
分析:涉及的对象为tb_a,变更指令为UPDATE,则回退指令为UPDATE,变更语句修改了数据表tb_a的字段col_b为原值增加100,且更新条件为字段col_b等于10,因此源数据的具体数据可以直接推导出,无需备份数据。Analysis: The object involved is tb_a, the change command is UPDATE, then the rollback command is UPDATE, the change statement modifies the field col_b of the data table tb_a to increase the original value by 100, and the update condition is that the field col_b is equal to 10, so the specific source data Data can be derived directly without backup data.
对应的回退语句:UPDATE tb_a SET col_b=col_b-100WHERE col_b=10;Corresponding rollback statement: UPDATE tb_a SET col_b=col_b-100WHERE col_b=10;
(b3)删除数据的回退(b3) Rollback of deleted data
如果变更语句为DELETE FROM tb_a WHERE c,其中,tb_a代表删除数据的对象,c代表删除数据对应的字段,删除数据的回退包括:If the change statement is DELETE FROM tb_a WHERE c, where tb_a represents the object of the deleted data, and c represents the field corresponding to the deleted data, the rollback of the deleted data includes:
S1b3、确定变更语句涉及的对象为tb_a,变更指令为:DELETE,DELETE对应的回退指令为INSERT;S1b3. Determine that the object involved in the change statement is tb_a, the change command is: DELETE, and the rollback command corresponding to DELETE is INSERT;
S2b3、变更语句进行删除操作,确定对应于c的源数据,确定回退语句为:INSERTINTO tb_a(col_a)VALUES d,其中,d代表源数据的具体数据,col_a代表源数据对应的字段;S2b3. Change the statement to perform a delete operation, determine the source data corresponding to c, and determine the rollback statement as: INSERTINTO tb_a(col_a)VALUES d, where d represents the specific data of the source data, and col_a represents the field corresponding to the source data;
例如:E.g:
b3-1)变更语句:b3-1) Change statement:
DELETE FROM tb_a WHERE col_a=1;DELETE FROM tb_a WHERE col_a=1;
分析:涉及的对象为tb_a,变更指令为DELETE,则回退指令为INSERT,变更语句删除了数据表tb_a所有col_a字段等于1的行,源数据包括所有col_a等于1的行中的数据,先通过如下语句查询表tb_a的列及顺序:Analysis: The object involved is tb_a, the change command is DELETE, and the rollback command is INSERT. The change statement deletes all the rows in the data table tb_a with the col_a field equal to 1. The source data includes all the data in the rows with col_a equal to 1. First pass The following statement queries the columns and order of table tb_a:
SELECT column_name FROM user_tab_columns WHERE table_name='tb_a'ORDERBY column_id;SELECT column_name FROM user_tab_columns WHERE table_name='tb_a' ORDER BY column_id;
假设如上语句查询结果为:Suppose the query result of the above statement is:
col_acol_a
col_bcol_b
col_ccol_c
则表明数据表tb_a的字段按顺序分别为col_a,col_b,col_c。再查询变更前待删除行的数据,通过如下语句获取:It indicates that the fields of the data table tb_a are col_a, col_b, and col_c in order. Then query the data of the row to be deleted before the change, and obtain it through the following statement:
SELECT col_a,col_b,col_c FROM tb_a WHERE col_a=1;SELECT col_a,col_b,col_c FROM tb_a WHERE col_a=1;
假设如上语句查询结果为:Suppose the query result of the above statement is:
1,10,‘A’1,10,'A'
1,10,‘B’1,10,'B'
1,20,‘C’1,20,'C'
根据查询到的列名及数据,可得到最终的变更回退语句。According to the queried column names and data, the final change rollback statement can be obtained.
对应的回退语句:The corresponding fallback statement:
INSERT INTO tb_a(col_a,col_b,col_c)VALUES(1,10,‘A’);INSERT INTO tb_a(col_a,col_b,col_c)VALUES(1,10,'A');
INSERT INTO tb_a(col_a,col_b,col_c)VALUES(1,10,‘B’);INSERT INTO tb_a(col_a,col_b,col_c)VALUES(1,10,'B');
INSERT INTO tb_a(col_a,col_b,col_c)VALUES(1,20,‘C’);INSERT INTO tb_a(col_a,col_b,col_c)VALUES(1,20,'C');
(b4)MERGE类数据变更语句的回退(b4) Rollback of MERGE data change statement
MERGE语句从源表向目标表根据条件处理数据,操作可能是INSERT,也可能是UPDATE,因此备份源数据时,也需要根据条件判断如何备份,以及备份哪些数据。The MERGE statement processes data from the source table to the target table according to the conditions. The operation may be INSERT or UPDATE. Therefore, when backing up the source data, it is also necessary to judge how to back up and which data to back up according to the conditions.
例如:E.g:
b4-1)变更语句:b4-1) Change statement:
分析:变更语句将源表tb_b的数据合并进目标表tb_a,如果tb_b表的字段col_a值等于tb_a的字段col_a值,则使用tb_b表的记录更新tb_a表的记录,否则,将源表tb_b中的记录插入到目标表tb_a中。Analysis: The change statement merges the data of the source table tb_b into the target table tb_a. If the value of the field col_a of the tb_b table is equal to the value of the field col_a of tb_a, the records of the tb_b table are used to update the records of the tb_a table, otherwise, the records of the source table tb_b are updated. Records are inserted into the target table tb_a.
进行变更回退时,需要先判断目标表tb_a中是否存在与源表tb_b中col_a字段值相同的记录,若存在,则表明这部分数据行被源表数据更新,因此需要备份这部分数据行以便恢复更新,可通过如下语句查询被更新数据行:When performing a change rollback, it is necessary to first determine whether there is a record in the target table tb_a with the same value as the col_a field in the source table tb_b. If it exists, it indicates that this part of the data row is updated by the source table data, so it is necessary to back up this part of the data row for To restore the update, you can use the following statement to query the updated data row:
SELECT a.col_a,a.col_b,a.col_c FROM tb_a a,tb_b b WHERE a.col_a=b.col_a;SELECT a.col_a,a.col_b,a.col_c FROM tb_a a,tb_b b WHERE a.col_a=b.col_a;
假设上述语句查询结果为:Assume that the query result of the above statement is:
1,2,31,2,3
1,2,4,1,2,4,
1,3,41,3,4
表明这些数据行被更新,为了回退源数据,还需要知道源数据被更新后的值,可通过如下语句获得被更新行更新后的值:Indicates that these data rows are updated. In order to roll back the source data, it is also necessary to know the updated value of the source data. The updated value of the updated row can be obtained through the following statement:
SELECT col_a,col_b,col_c FROM tb_b b WHERE EXISTS(SELECT1FROM tb_a aWHERE a.col_a=b.col_a);SELECT col_a,col_b,col_c FROM tb_b b WHERE EXISTS(SELECT1 FROM tb_a aWHERE a.col_a=b.col_a);
假设查询结果为:Suppose the query result is:
1,5,91, 5, 9
表明被更新行都被更新为1,5,9。根据变更前和变更后的数据,即可得到最终的回退语句。Indicates that the updated rows are all updated to 1, 5, and 9. According to the data before and after the change, the final rollback statement can be obtained.
源数据除了更新行之外,还包括目标表中新增的行,在进行回退时,这部分新增行应该被删除。可通过如下语句查询新增行:In addition to updated rows, the source data also includes new rows in the target table. When rolling back, these new rows should be deleted. New rows can be queried by the following statement:
SELECT col_a,col_b,col_c FROM tb_b b WHERE NOT EXISTS(SELECT 1 FROMtb_a a WHERE a.col_a=b.col_a);SELECT col_a,col_b,col_c FROM tb_b b WHERE NOT EXISTS(SELECT 1 FROM tb_a a WHERE a.col_a=b.col_a);
假设上述语句查询结果为:Assume that the query result of the above statement is:
3,3,63,3,6
回退语句:Fallback statement:
DELETE FROM tb_a WHERE col_a=1AND col_b=5AND col_c=9;DELETE FROM tb_a WHERE col_a=1AND col_b=5AND col_c=9;
INSERT INTO tb_a(col_a,col_b,col_c)VALUES(1,2,3);INSERT INTO tb_a(col_a,col_b,col_c)VALUES(1,2,3);
INSERT INTO tb_a(col_a,col_b,col_c)VALUES(1,2,4);INSERT INTO tb_a(col_a,col_b,col_c)VALUES(1,2,4);
INSERT INTO tb_a(col_a,col_b,col_c)VALUES(1,3,4);INSERT INTO tb_a(col_a,col_b,col_c)VALUES(1,3,4);
DELETE FROM tb_a WHERE col_a=3AND col_b=3AND col_c=6;DELETE FROM tb_a WHERE col_a=3AND col_b=3AND col_c=6;
(b5)具有复杂变更条件的数据变更语句的回退(b5) Rollback of data change statements with complex change conditions
在所有的SQL语句中,DML语句可以表现为最复杂的形式。DML语句可以包含表连接、子查询、集合运算等多种操作,给执行DML回退时带来了较高的复杂度,但无论DML语句有多么复杂,需要回退的最终操作仍然不过INSERT、UPDATE、DELETE三种情况,其复杂主要体现在复杂的约束条件上。因此只要准确的分析DML语句结构,在备份源数据时加上约束条件,就能准确的得到回退语句。如下示例说明复杂DML语句的逆向分析机制。Among all SQL statements, DML statements can be expressed in the most complex form. DML statements can contain multiple operations such as table joins, subqueries, and set operations, which brings high complexity to the implementation of DML rollback. However, no matter how complex the DML statement is, the final operations that need rollback are still no more than INSERT, The complexity of UPDATE and DELETE is mainly reflected in the complex constraints. Therefore, as long as the DML statement structure is accurately analyzed and constraints are added when backing up the source data, the rollback statement can be accurately obtained. The following example illustrates the reverse analysis mechanism of complex DML statements.
例如:E.g:
b5-1)变更语句:b5-1) Change statement:
分析:该语句比较复杂,包含了子查询、集合操作,但从语句体可以看出,其核心操作还是第一行INSERT语句,从第二行开始的SELECT语句到结尾,全部是待INSERT的数据查询语句,所以备份源数据时,只需要备份SELECT处理的数据,我们执行如下SELECT语句获得待备份的源数据:Analysis: This statement is relatively complicated, including subqueries and set operations, but it can be seen from the body of the statement that its core operation is still the INSERT statement on the first line. From the SELECT statement on the second line to the end, all the data to be INSERT query statement, so when backing up source data, only the data processed by SELECT needs to be backed up. We execute the following SELECT statement to obtain the source data to be backed up:
假设如上语句查询结果为:Suppose the query result of the above statement is:
1,5,91,5,9
2,6,32,6,3
2,6,42,6,4
对应的回退语句:The corresponding fallback statement:
DELETE FROM tb_a WHERE col_a=1AND col_b=5AND col_c=9;DELETE FROM tb_a WHERE col_a=1AND col_b=5AND col_c=9;
DELETE FROM tb_a WHERE col_a=2AND col_b=6AND col_c=3;DELETE FROM tb_a WHERE col_a=2AND col_b=6AND col_c=3;
DELETE FROM tb_a WHERE col_a=2AND col_b=6AND col_c=4;DELETE FROM tb_a WHERE col_a=2AND col_b=6AND col_c=4;
(b6)可包含重复行的表数据变更的回退(b6) Rollback of table data changes that can contain duplicate rows
可包含重复行的表,通常是表没有主键或唯一性约束,这样的数据表中可以存在多条数据完全一致的记录行,对这种表的回退需要考虑可能存在重复行的情况,会影响到INSERT和UPDATE语句的回退。Tables that can contain duplicate rows usually have no primary key or uniqueness constraints. In such a data table, there may be multiple record rows with completely consistent data. The rollback of such a table needs to consider the possible existence of duplicate rows, which will Affects fallback for INSERT and UPDATE statements.
就INSERT语句,如果插入了一行记录,而表中本来就有一行相同的记录, 那么简单的执行DELETE回退,就会把原来的记录行也删除。因此对于此种情况,我们需要先判断表是否有主键或唯一性约束,可通过如下语句查询:As for the INSERT statement, if a row of records is inserted, and there is already a row of the same record in the table, then simply execute DELETE to roll back, and the original row of records will also be deleted. Therefore, in this case, we need to first determine whether the table has a primary key or a unique constraint, which can be queried by the following statement:
SELECT*FROM user_constraints WHERE constraint_type IN('P','U')ANDtable_name='tb_a';SELECT*FROM user_constraints WHERE constraint_type IN('P','U')ANDtable_name='tb_a';
如果上述查询无返回结果,则表明该表可能存在重复记录,那么此时源数据的备份为全表备份,而不能只备份INSERT的记录行,执行回退时先进行全表删除然后进行备份数据的全表插入。If the above query does not return results, it indicates that there may be duplicate records in the table. At this time, the backup of the source data is a full table backup, not just the INSERT record rows. When performing a rollback, first delete the entire table and then back up the data The full table insert.
就UPDATE语句,针对可重复记录行的表,如果UPDATE语句将表中多行记录更新为完全相同的记录,那么在回退UPDATE时可能会出现数据不可恢复的情况。某些数据库具有固定的行标识如Oracle ROWID,则可通过备份系统行标识来确定回退行,如没有行标识字段,则源数据的备份需要进行全表备份。Regarding the UPDATE statement, for a table with repeatable rows, if the UPDATE statement updates multiple records in the table to exactly the same records, then the data may not be recoverable when the UPDATE is rolled back. Some databases have a fixed row identifier such as Oracle ROWID, and the rollback row can be determined through the backup system row identifier. If there is no row identifier field, the backup of the source data requires a full table backup.
(c1)授权语句的回退(c1) Fallback of authorization statement
如果变更语句为GRANT A USER TO user_a,授权语句的回退包括:If the change statement is GRANT A USER TO user_a, the fallback of the authorization statement includes:
S1c1、确定变更语句涉及的对象为user_a,变更指令为:GRANT,对应的回退指令为REVOKE;S1c1. Determine that the object involved in the change statement is user_a, the change command is: GRANT, and the corresponding rollback command is REVOKE;
S2c1、变更语句进行授权操作,与权限相关的授权操作或者权限回收操作都相当于创建/增加操作,授权操作相当于增加或者创建一个权限,权限回收操作则相当于增加或者创建一个“负”权限,因此,这两种情况都不用确定源数据或者源内容,直接确定回退语句为:REVOKE A FROM user_a;S2c1. Change statements to perform authorization operations. Permission-related authorization operations or permission recovery operations are equivalent to creating/adding operations. Authorization operations are equivalent to adding or creating a permission, and permission recovery operations are equivalent to adding or creating a "negative" permission. , therefore, in both cases, there is no need to determine the source data or source content, and the rollback statement is directly determined as: REVOKE A FROM user_a;
例如:E.g:
c1-1)变更语句:GRANT CREATE SESSION,CREATE USER TO user_a;c1-1) Change statement: GRANT CREATE SESSION, CREATE USER TO user_a;
对应的回退语句:REVOKE CREATE SESSION,CREATE USER FROM user_a;Corresponding rollback statement: REVOKE CREATE SESSION, CREATE USER FROM user_a;
(c2)权限回收语句的回退(c2) Rollback of permission recovery statement
如果变更语句为REVOKE A ON tb_a FROM role_a;权限回收语句的回退包括:If the change statement is REVOKE A ON tb_a FROM role_a; the rollback of the permission recovery statement includes:
S1c1、确定变更语句涉及的对象为role_a,变更指令为:REVOKE,对应的回退指令为GRANT;S1c1. Determine that the object involved in the change statement is role_a, the change command is: REVOKE, and the corresponding rollback command is GRANT;
S2c1、变更语句进行权限回收操作,直接确定回退语句为:GRANT A ON tb_a TOrole_a。S2c1. Change the statement to perform the authority recovery operation, and directly determine the rollback statement as: GRANT A ON tb_a TOrole_a.
例如:E.g:
C2-1)变更语句:REVOKE SELECT,INSERT,UPDATE,DELETE ON tb_a FROM role_a;C2-1) Change statement: REVOKE SELECT, INSERT, UPDATE, DELETE ON tb_a FROM role_a;
对应的回退语句:GRANT SELECT,INSERT,UPDATE,DELETE ON tb_a TO role_a;Corresponding rollback statement: GRANT SELECT, INSERT, UPDATE, DELETE ON tb_a TO role_a;
综上可见,如果手工执行回退分析,其复杂度和工作量会很大,本发明针对复杂的回退分析过程,建立了一套自动化、智能、准确的分析方法和系统,利用上述逆向分析方法,在获得变更脚本输入后,整个分析过程无需人工干预,便可生成最终的回退脚本。在执行回退时,简单的通过调用回退脚本即可自动完成数据库变更回退。To sum up, it can be seen that if the rollback analysis is performed manually, the complexity and workload will be very large. The present invention has established a set of automatic, intelligent, and accurate analysis methods and systems for the complex rollback analysis process. Using the above reverse analysis method, after obtaining the input of the change script, the entire analysis process can generate the final rollback script without manual intervention. When performing a rollback, the database change rollback can be automatically completed simply by calling the rollback script.
参考图2A是本发明数据库变更回退方法的第一实施例的流程图;图2B是本发明数据库变更回退方法的第二实施例的流程图;Referring to FIG. 2A is a flow chart of the first embodiment of the database change rollback method of the present invention; FIG. 2B is a flow chart of the second embodiment of the database change rollback method of the present invention;
本发明的数据库变更回退方法包括:The database change rollback method of the present invention comprises:
S10、获得SQL变更脚本输入、数据库版本和数据库授权;S10, obtaining SQL change script input, database version and database authorization;
SQL变更脚本的执行用户的数据库授权小于数据库权限,SQL变更脚本为包含变更语句的文本文件,数据库授权包括数据库用户名和密码;The database authorization of the user who executes the SQL change script is less than the database authority, the SQL change script is a text file containing the change statement, and the database authorization includes the database user name and password;
S20、对SQL变更脚本执行解析,生成语句解析结果;为根据所述SQL变 更脚本调用所述数据库版本的SQL引擎执行Flex词法分析和Bison语法分析。S20, execute parsing to SQL change script, generate statement parsing result; For the SQL engine that calls described database version according to described SQL change script, perform Flex lexical analysis and Bison syntax analysis.
传统的语言解析方法,是首先按照规则,将文本中的字符串划分为一个个符号Token,Token主要有两种属性,Token名称Token Name,Token值Token Value,对整个文件的不断处理会连续的输出Token流,整个过程称之为词法分析。词法分析概括起来说,就是定义Token类型和划分规则,并执行分析获得Token流的过程。The traditional language parsing method is to first divide the strings in the text into tokens according to the rules. Tokens mainly have two attributes, the token name Token Name, and the token value Token Value. The continuous processing of the entire file will be continuous Token stream is output, and the whole process is called lexical analysis. In a nutshell, lexical analysis is the process of defining Token types and division rules, and performing analysis to obtain Token streams.
语法分析是根据定义的语法规则,获得输入的Token流,进行语法树构建,最终识别语句的过程。本发明的方案支持Oracle、MySQL、Sybase和SQL Server大部分常见语句,且可以通过扩展SQL引擎,支持新的数据库类型,扩展词法与语法规则,支持新的语句类型。Grammatical analysis is the process of obtaining the input Token stream according to the defined grammatical rules, constructing a grammatical tree, and finally identifying sentences. The scheme of the present invention supports most common statements of Oracle, MySQL, Sybase and SQL Server, and can support new database types, extended lexical and grammatical rules, and support new statement types by extending the SQL engine.
下面以SQL语句中常见的INSERT语句为例,介绍SQL引擎的工作方法和流程。The following uses common INSERT statements in SQL statements as an example to introduce the working method and process of the SQL engine.
(a)词法分析(a) Lexical analysis
假设要向数据表tb_a中插入一行数据(1,2,‘test’),存在如下两种写法,且都是合法的INSERT语句。Suppose you want to insert a row of data (1,2,'test') into the data table tb_a, there are the following two ways of writing, and both are legal INSERT statements.
INSERT INTO tb_a VALUES(1,2,'test');INSERT INTO tb_a VALUES(1,2,'test');
INSERT INTO tb_a(col_a,col_b)VALUES(1,'test');INSERT INTO tb_a(col_a,col_b)VALUES(1,'test');
在上述语句中,可以发现如下规律:In the above sentences, the following rules can be found:
1、INSERT语句必须以INSERT INTO关键字开始;1. The INSERT statement must start with the INSERT INTO keyword;
2、接下来必须跟上待插入数据的表名,此处假设表名只能是字母、数字、下划线的组合,且必须以字母开头;2. Next, you must keep up with the table name of the data to be inserted. Here, it is assumed that the table name can only be a combination of letters, numbers, and underscores, and must start with a letter;
3、表名后可以包含列名,也可以不包含列名。不包含列名表示所有列,包含列名则必须以左括号开始,右括号结束,列名以逗号分隔。此处同样假设 列名只能是字母、数字、下划线的组合,且必须以字母开头;3. The column name may or may not be included after the table name. Do not include the column name means all columns, if you include the column name, you must start with an opening bracket and end with a closing bracket, and the column names are separated by commas. It is also assumed here that the column name can only be a combination of letters, numbers, and underscores, and must start with a letter;
4、之后是VALUES子句;4, followed by the VALUES clause;
5、VALUES子句后,是具体的待插入值,以左括号开始,右括号结束,多个值以逗号分隔,如果值为字符串,以引号开始,引号结束。5. After the VALUES clause, it is the specific value to be inserted. It starts with a left parenthesis and ends with a right parenthesis. Multiple values are separated by commas. If the value is a string, it starts with a quotation mark and ends with a quotation mark.
根据如上分析结果,可以总结如表1所示的INSERT语句的Token类型。According to the above analysis results, the Token types of INSERT statements as shown in Table 1 can be summarized.
表1Table 1
Flex使用基于正则表达式的词法匹配规则,那么此处针对如上INSERT语句,定义的Flex词法文件如下:Flex uses regular expression-based lexical matching rules, so for the above INSERT statement, the defined Flex lexical file is as follows:
[Ii][Nn][Ss][Ee][Rr][Tt] {return INSERT;}[Ii][Nn][Ss][Ee][Rr][Tt] {return INSERT;}
[Ii][Nn][Tt][Oo] {return INTO;}[Ii][Nn][Tt][Oo] {return INTO;}
[Vv][Aa][Ll][Uu][Ee][Ss] {return VALUES;}[Vv][Aa][Ll][Uu][Ee][Ss] {return VALUES;}
"("|")"|","|";" {return yytext[0];}"("|")"|","|";" {return yytext[0];}
[A-Za-z][A-Za-z0-9_]* {return NAME;}[A-Za-z][A-Za-z0-9_]* {return NAME;}
[0-9]+ {return NUMBER;}[0-9]+{return NUMBER;}
"'"[^"'"\n]*"'" {return STRING;}"'"[^"'"\n]*"'" {return STRING;}
[\t][\t]
. {yyerror("匹配失败");}.{yyerror("Match failed");}
根据如上词法文件,对上述第一条INSERT语句的词法分析结果如表2。According to the above lexical file, the lexical analysis results of the above first INSERT statement are shown in Table 2.
表2Table 2
(b)语法分析(b) Syntactic analysis
不同的语言有不同的语法,SQL语言也是如此。就SQL语言来说,虽然存在SQL国际标准,但是不同的数据库厂商对自身的数据库产品往往进行了一些增强和扩展,所以对不同的数据库类型,语法也具有一些差异。进行语法分析前,首先要确定语言的语法规则,然后才能根据规则分析输入语句。Different languages have different syntax, and so does the SQL language. As far as the SQL language is concerned, although there is an international SQL standard, different database vendors often enhance and expand their own database products, so there are some differences in syntax for different database types. Before grammatical analysis, the grammatical rules of the language must be determined first, and then the input sentences can be analyzed according to the rules.
在Bison中,对语法规则的定义是主要是通过词法分析输出的Token来完成的。Token是语法规则的基本元素,在语法分析的范畴内,Token被称为终结符,通过终结符建立最终的有语义的语句。同样以上述INSERT语句为例,In Bison, the definition of grammatical rules is mainly done through the Token output by lexical analysis. Token is the basic element of grammatical rules. In the scope of grammatical analysis, Token is called a terminator, and the final semantic statement is established through the terminator. Also take the above INSERT statement as an example,
说明语法解析的方法和过程。Explain the method and process of grammar analysis.
首先,根据SQL语句格式定义如下INSERT语法规则:First, define the following INSERT syntax rules according to the SQL statement format:
根据上述语法规则,对语句“INSERT INTO tb_a(col_a,col_b)VALUES(1,'test');”的语法解析过程如图3所示。方框内的叶子节点为终结符,终结符均是词法分析的输出,树上的椭圆形节点均为非终结符,树的结构则展示了语句的语法规则。不仅是INSERT语句,其他的任何SQL语句都可以通过定义语法规则来完成语义解析。According to the above grammatical rules, the grammatical parsing process of the statement "INSERT INTO tb_a(col_a,col_b)VALUES(1,'test');" is shown in Figure 3. The leaf nodes in the box are terminal symbols, and the terminal symbols are the output of lexical analysis. The oval nodes on the tree are all non-terminal symbols, and the tree structure shows the grammatical rules of the statement. Not only the INSERT statement, but any other SQL statement can complete semantic analysis by defining grammatical rules.
S30、基于语句解析结果,根据变更语句逆向分析方法生成回退语句并将回退语句转换为可执行的回退SQL脚本文件。S30. Based on the statement analysis result, a rollback statement is generated according to the reverse analysis method of the change statement, and the rollback statement is converted into an executable rollback SQL script file.
SQL语句通常是顺序执行的,具有语句级别的前后依赖关系,因此在对变更语句进行逆向分析时,需要从最后一条语句开始,逆序分析直到第一条语句。SQL statements are usually executed sequentially and have statement-level dependencies. Therefore, when performing reverse analysis on a change statement, it is necessary to start from the last statement and perform reverse analysis until the first statement.
假设当前数据库环境为Oracle,数据表tb_a无主键和唯一性索引,表中存在与带插入数据重复的记录行。对上述INSERT语句的逆向分析过程如表3所示。Assume that the current database environment is Oracle, the data table tb_a has no primary key and unique index, and there are duplicate rows with inserted data in the table. The reverse analysis process of the above INSERT statement is shown in Table 3.
表3table 3
上表Token名值两列标识输入的Token类型和值,回退逻辑输出列显示了逆向分析的结果。不光是INSERT语句,其他SQL语句同样适合类似的分析方法。The two columns of Token name and value in the above table identify the type and value of the input Token, and the fallback logic output column shows the results of the reverse analysis. Not only INSERT statements, other SQL statements are also suitable for similar analysis methods.
上述步骤S10-S30仅仅是生成了回退SQL脚本文件,并未执行备份,在需要进行备份时,还进一步包括以下步骤:The above steps S10-S30 only generate the rollback SQL script file, but do not perform backup. When backup is required, the following steps are further included:
S40、输入回退执行命令,运行回退SQL脚本文件实现数据库变更回退。S40. Input a rollback execution command, and run the rollback SQL script file to roll back the database change.
关于步骤S30中根据变更语句逆向分析方法生成的回退语句为由若干子句构成的逻辑回退语句,步骤S30将回退语句转换为可执行的回退SQL脚本文件具体包括:Regarding the rollback statement generated according to the reverse analysis method of the change statement in step S30 is a logical rollback statement composed of several clauses, the step S30 converts the rollback statement into an executable rollback SQL script file specifically includes:
S31、重组:对子句进行重新组织;S31. Reorganization: reorganize the clauses;
回退语句的结构通常与变更语句不同,因此需要对子句进行重新组织。A rollback statement usually has a different structure than an alter statement, so the clauses need to be reorganized.
S32、填充:将重组后的子句填充后形成完整且合法的SQL语句;S32. Filling: filling the reorganized clauses to form a complete and legal SQL statement;
不同的语句语法格式不尽相同,某些语法单元无法通过逆向分析得出,需要系统根据语句的语法和语义自动补充,如DELETE语句的FROM,条件子句的WHERE,多个条件语句之间的AND或OR逻辑关系等。填充后的语句才是完整合法的回退SQL语句。The grammatical format of different statements is not the same, and some grammatical units cannot be obtained through reverse analysis, and need to be automatically supplemented by the system according to the syntax and semantics of the statement, such as the FROM of the DELETE statement, the WHERE of the conditional clause, and the AND or OR logical relationship, etc. The filled statement is a complete and legal fallback SQL statement.
S33、映射:将步骤S32中得到的具有不同实现的SQL语句映射为特定数据库系统的语句;S33. Mapping: mapping the SQL statements with different implementations obtained in step S32 into statements of a specific database system;
不同的数据库系统有不同的语法,同样的逻辑语句在不同的数据库系统里可能有不同的实现,系统需要将具有不同实现的语句映射为特定数据库系统的语句。如语句分隔符,在Oracle、MySQL数据库里为分号,在Sybase、SQLServer 数据库里为go;Different database systems have different grammars, and the same logic statement may have different implementations in different database systems. The system needs to map statements with different implementations to statements of a specific database system. For example, the statement delimiter is semicolon in Oracle and MySQL databases, and go in Sybase and SQLServer databases;
S34、合并:将数据导入命令和步骤S33中得到的语句合并为回退SQL脚本文件。S34. Merge: merge the data import command and the statement obtained in step S33 into a fallback SQL script file.
如上四个步骤为实体回退时,回退SQL脚本文件生成的过程,某些过程可能是可选的,实际处理过程中,会根据语句的特征进行特定的处理。如表4示例展示了INSERT语句回退脚本文件生成的过程。When the above four steps are entity rollback, the rollback SQL script file generation process may be optional. In the actual processing process, specific processing will be performed according to the characteristics of the statement. The example in Table 4 shows the process of generating the INSERT statement rollback script file.
表4Table 4
本发明还公开了一种基于上述的数据库变更回退方法的数据库变更回退 系统,参考图4是本发明数据库变更回退系统的架构层次图,系统包括:The present invention also discloses a database change rollback system based on the above-mentioned database change rollback method. Referring to FIG. 4 is a hierarchical diagram of the database change rollback system of the present invention. The system includes:
用户接口层100:用于与用户进行交互处理;交互处理包括获得SQL变更脚本输入、数据库版本、数据库授权以及回退执行命令;User interface layer 100: used for interactive processing with users; interactive processing includes obtaining SQL change script input, database version, database authorization, and rollback execution commands;
回退处理层200:用于对SQL变更脚本执行解析,生成语句解析结果,并基于语句解析结果根据变更语句逆向分析方法生成回退语句,并将回退语句转换为可执行的回退SQL脚本文件;Rollback processing layer 200: used to analyze the SQL change script, generate statement analysis results, and generate rollback statements based on the statement analysis results according to the reverse analysis method of the change statement, and convert the rollback statements into executable rollback SQL scripts document;
数据服务层300:用于从数据库查询数据、进行源数据/源内容备份,以及在接收到回退执行命令时执行回退SQL脚本文件;Data service layer 300: for querying data from the database, backing up source data/source content, and executing a rollback SQL script file when a rollback execution command is received;
数据库层400:提供数据库系统。Database layer 400: providing a database system.
参考图5是本发明数据库变更回退系统的系统组件图。Referring to FIG. 5 is a system component diagram of the database change rollback system of the present invention.
用户接口层100的功能组件包括:The functional components of the user interface layer 100 include:
命令处理组件101:用于接收SQL变更脚本和回退执行命令;Command processing component 101: used to receive SQL change scripts and rollback execution commands;
信息交互组件102:用于将数据库回退的过程与结果展示给用户;Information interaction component 102: used to display the process and results of database rollback to the user;
回退处理层200的功能组件包括:The functional components of the fallback processing layer 200 include:
SQL引擎201:根据数据库的词法和语法规则,完成SQL变更脚本的解析并生成语句解析结果,SQL变更脚本的解析包括词法分析和语法分析,其中,词法解析采用Flex工具,语法解析采用Bison工具;SQL engine 201: according to the lexical and grammatical rules of the database, complete the parsing of the SQL change script and generate a statement parsing result, the parsing of the SQL change script includes lexical analysis and grammatical analysis, wherein the lexical analysis adopts the Flex tool, and the grammatical analysis adopts the Bison tool;
脚本解析组件202:用于根据数据库类型调用对应的SQL引擎201完成SQL变更脚本的解析,并负责解析过程的错误处理;Script parsing component 202: used for invoking the corresponding SQL engine 201 according to the database type to complete the parsing of the SQL change script, and responsible for error handling during the parsing process;
逆向分析组件203:用于分析语句解析结果,根据变更语句逆向分析方法生成回退语句;Reverse analysis component 203: used for analyzing the statement analysis result, and generating a rollback statement according to the reverse analysis method of the change statement;
回退语句生成组件204:用于结合数据服务层300,将回退语句转换为和数据库类型相关的SQL回退语句,并将生成的回退SQL脚本文件提 供给数据服务层300;Rollback statement generating component 204: used to combine the data service layer 300, convert the rollback statement into an SQL rollback statement relevant to the database type, and provide the generated rollback SQL script file to the data service layer 300;
数据服务层300包括:The data service layer 300 includes:
数据查询组件301:用于从数据库获得SQL回退语句并生成需要的数据;数据备份组件302:用于对回退需要备份的源数据/源内容进行备份和管理;Data query component 301: used to obtain SQL rollback statements from the database and generate required data; data backup component 302: used to back up and manage source data/source content that needs to be backed up for rollback;
脚本执行组件303:用于获取回退SQL脚本文件,完成回退SQL脚本文件的执行;Script execution component 303: used to obtain the rollback SQL script file, and complete the execution of the rollback SQL script file;
数据库层400包括:Oracle、MySQL、Sybase、SQL Server系统。The database layer 400 includes: Oracle, MySQL, Sybase, SQL Server systems.
综上所述,本发明的变更语句逆向分析方法在所述变更语句执行之前进行逆向分析生成回退语句,回退语句仅仅对变更语句涉及的对象或者对象的源数据/源内容进行回退,针对性强,工作量小。数据库变更回退方法利用该方法生成的回退语句,转换为可执行的回退SQL脚本文件,在需要进行数据库的回退时,执行回退SQL脚本文件即可,达到了适用性广、可操作性强、安全、高效自动化的优点。To sum up, the reverse analysis method of the change statement of the present invention performs reverse analysis before the execution of the change statement to generate a rollback statement, and the rollback statement only rolls back the object involved in the change statement or the source data/source content of the object, Strong pertinence and low workload. The database change rollback method uses the rollback statement generated by this method to convert it into an executable rollback SQL script file. When it is necessary to roll back the database, just execute the rollback SQL script file, achieving wide applicability and reliability. The advantages of strong operability, safety, and high-efficiency automation.
上面结合附图对本发明的实施例进行了描述,但是本发明并不局限于上述的具体实施方式,上述的具体实施方式仅仅是示意性的,而不是限制性的,本领域的普通技术人员在本发明的启示下,在不脱离本发明宗旨和权利要求所保护的范围情况下,还可做出很多形式,这些均属于本发明的保护之内。Embodiments of the present invention have been described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementations, and the above-mentioned specific implementations are only illustrative, rather than restrictive, and those of ordinary skill in the art will Under the enlightenment of the present invention, many forms can also be made without departing from the gist of the present invention and the protection scope of the claims, and these all belong to the protection of the present invention.
Claims (7)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201310634777.9A CN103678532B (en) | 2013-12-02 | 2013-12-02 | Alternation statement reverse analysis method, database alternating and backspacing method and database alternating and backspacing system |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201310634777.9A CN103678532B (en) | 2013-12-02 | 2013-12-02 | Alternation statement reverse analysis method, database alternating and backspacing method and database alternating and backspacing system |
Publications (2)
Publication Number | Publication Date |
---|---|
CN103678532A CN103678532A (en) | 2014-03-26 |
CN103678532B true CN103678532B (en) | 2017-05-10 |
Family
ID=50316077
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201310634777.9A Active CN103678532B (en) | 2013-12-02 | 2013-12-02 | Alternation statement reverse analysis method, database alternating and backspacing method and database alternating and backspacing system |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN103678532B (en) |
Families Citing this family (16)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105550178A (en) * | 2014-10-29 | 2016-05-04 | 中兴通讯股份有限公司 | Database processing method and device and system |
CN105740131B (en) * | 2014-12-09 | 2020-09-25 | 深圳力维智联技术有限公司 | Software user behavior rollback processing method and device |
CN106970855B (en) * | 2016-01-14 | 2021-04-20 | 华为技术有限公司 | Method and apparatus for data recovery |
CN107220315B (en) * | 2017-05-16 | 2020-08-25 | 北京酷我科技有限公司 | User data protection method for database degradation during APP version updating |
CN107329854A (en) * | 2017-06-20 | 2017-11-07 | 算丰科技(北京)有限公司 | Operation repealing method and device, electronic equipment |
CN110019118A (en) * | 2017-09-28 | 2019-07-16 | 广东亿迅科技有限公司 | The system and method for database O&M efficiency are promoted based on DevOps |
CN107844387A (en) * | 2017-10-17 | 2018-03-27 | 广东广业开元科技有限公司 | A kind of conventional data backup method, system and device |
CN108052681B (en) * | 2018-01-12 | 2020-05-26 | 毛彬 | Method and system for synchronizing structured data between relational databases |
CN109656935B (en) * | 2018-11-23 | 2023-12-01 | 创新先进技术有限公司 | Method and system for data playback of a database |
CN111382170B (en) * | 2018-12-29 | 2023-07-14 | 北京亿阳信通科技有限公司 | Sentence automatic conversion method and device |
CN111221918A (en) * | 2019-11-04 | 2020-06-02 | 深圳力维智联技术有限公司 | Data updating method, device, product and medium based on relational database |
CN111176891A (en) * | 2019-12-22 | 2020-05-19 | 北京浪潮数据技术有限公司 | Method, device and equipment for recovering configuration information of baseboard management controller |
CN111221846B (en) * | 2020-01-06 | 2023-09-29 | 广州拉卡拉信息技术有限公司 | Automatic translation method and device for SQL sentences |
CN112883050B (en) * | 2021-02-25 | 2024-03-08 | 中国工商银行股份有限公司 | Data changing method and device of database |
CN113792027B (en) * | 2021-08-23 | 2023-06-16 | 浙江金惠科技有限公司 | General database conversion device |
CN113672626B (en) * | 2021-09-06 | 2024-02-13 | 中国银行股份有限公司 | Data structure changing method and device and electronic equipment |
Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6480848B1 (en) * | 1999-07-19 | 2002-11-12 | International Business Machines Corporation | Extension of data definition language (DDL) capabilities for relational databases for applications issuing DML and DDL statements |
Family Cites Families (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7281023B2 (en) * | 2003-12-15 | 2007-10-09 | At&T Knowledge Ventures, L.P. | Architecture of database application with robust online recoverability |
US20080147596A1 (en) * | 2006-12-18 | 2008-06-19 | Mckenna William | Method and system for improving sql database query performance |
US20080249988A1 (en) * | 2007-04-06 | 2008-10-09 | International Business Machines Corporation | Computer programming method and system for performing a reversal of selected structured query language operations within a database transaction |
CN101425091A (en) * | 2008-12-05 | 2009-05-06 | 中国工商银行股份有限公司 | Database access path efficiency analyzing and processing method, server and system |
US8825601B2 (en) * | 2010-02-01 | 2014-09-02 | Microsoft Corporation | Logical data backup and rollback using incremental capture in a distributed database |
CN102609451B (en) * | 2012-01-11 | 2014-12-17 | 华中科技大学 | SQL (structured query language) query plan generation method oriented to streaming data processing |
-
2013
- 2013-12-02 CN CN201310634777.9A patent/CN103678532B/en active Active
Patent Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6480848B1 (en) * | 1999-07-19 | 2002-11-12 | International Business Machines Corporation | Extension of data definition language (DDL) capabilities for relational databases for applications issuing DML and DDL statements |
Non-Patent Citations (1)
Title |
---|
"oracle的回滚和撤销机制";无名增士_994;《新浪博客》;20111104;第1页 * |
Also Published As
Publication number | Publication date |
---|---|
CN103678532A (en) | 2014-03-26 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN103678532B (en) | Alternation statement reverse analysis method, database alternating and backspacing method and database alternating and backspacing system | |
CN109033410B (en) | SQL (structured query language) analysis method based on regular and character string cutting | |
US9430523B2 (en) | Entity-relationship model extensions using annotations | |
CN105868204B (en) | A kind of method and device for converting Oracle scripting language SQL | |
CN117093599A (en) | Unified SQL query method for heterogeneous data sources | |
CN109840256A (en) | A kind of inquiry implementation method based on Business Entity | |
US20150046389A1 (en) | Post-migration validation of etl jobs and exception management | |
CN113467785B (en) | SQL translation method and system for mimicry database | |
CN110019291A (en) | A kind of SQL analytic method and SQL resolver | |
CN104915341A (en) | Visual multi-database ETL integration method and system | |
CN105354036A (en) | Database operation code generating method and apparatus | |
CN111367893A (en) | Method and device for database version iteration | |
CN114003231B (en) | SQL syntax parse tree optimization method and system | |
CN105302842A (en) | Data processing method and device | |
Keim et al. | Object-oriented querying of existing relational databases | |
CN111914028A (en) | Method and device for synchronizing data relation of heterogeneous data sources based on graph increment | |
Künzner et al. | A comparison of different forms of temporal data management | |
US10810188B2 (en) | Load committed isolation processing | |
CN114357051B (en) | SQL and NoSQL data conversion method based on native JSON | |
EP4200698B1 (en) | Method and apparatus for mapping java streams to jpa commands | |
CN105426459A (en) | Unirecord index retrieval mode of distributed data of the Internet of things based on NoSQL database | |
CN110688367A (en) | A general database migration adaptation method and system | |
CN112445867A (en) | Intelligent analysis method and system for data relationship | |
CN104252357A (en) | SQL (Structural Query Language) language resolving method and SQL language resolving device | |
CN116010429A (en) | A database data processing method, system, storage medium and electronic equipment |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
CP03 | Change of name, title or address |
Address after: 518048 Guangdong province Futian District Shenzhen City Binhe Road, No. 9023, building 11, 41 layers of the country through the Patentee after: Medium shift information technology Co., Ltd. Address before: 518048 Guangdong, Shenzhen Binhe Road, No. 9023 building, state building, floor, No. 14 Patentee before: China Mobile (Shenzhen) Co., Ltd. |
|
CP03 | Change of name, title or address |