Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the responsive-lightbox domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the hueman domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114
Backup Table in SQL - Testingpool

Backup Table in SQL

Backup Table in SQL, as the name suggests, is the copy of an existing table whose backup we need to take .

Constraints on the original table are not copied in the Backup table except Not Null Constraint.

Indexes on the original table are not copied in the Backup table.

Syntax for Creating Backup Table:

Backup Table containing all the columns from the original table –

CREATE TABLE <Backup TableName> AS SELECT   *   FROM  <Existing Tablename>;

CREATE TABLE <Backup TableName> AS SELECT  <Col1 >, <Col2>…<ColN>  FROM  <Existing Tablename>;

 

Backup Table containing selected columns from the original table based on certain conditions –

CREATE TABLE <Backup TableName> AS SELECT  *  FROM  <Existing Tablename> WHERE <Condition> ;

 

Backup Table containing selected columns from the original table based on certain conditions –

CREATE TABLE <Backup TableName> AS SELECT  <Col1> , <Col2>…<ColN>

FROM  <Existing Tablename> WHERE <Condition> ;

 

To Copy only Structure ( all the columns) and not the data of the Original table in Backup Table –

CREATE TABLE <Backup TableName> AS SELECT  * FROM  <Existing Tablename> WHERE 0=1 ;

 

To Copy only Structure ( selected columns) and not the data of the Original table in Backup Table –

CREATE TABLE <Backup TableName> AS SELECT  <Col1> , <Col2>….<ColN>  FROM  <Existing Tablename> WHERE 0=1 ;

Note : Instead of the condition “0=1”, any other condition equating mismatch numbers can be given like 3=4, 6=8 etc.

Syntax to Load entire Data into Original Table from Backup Table :

INSERT INTO <Tablename> SELECT * FROM <Backup Tablename> ;

Syntax to Load entire Data into Original Table from Backup Table :

INSERT INTO <Tablename> (<col1> , <col2>…<colN>) SELECT  (<col1> , <col2>…<colN>)

FROM  <Backup Tablename> ;

Note : The number and datatypes of columns in both backup table and destination table should be same.

INSERT INTO <Tablename> (<col1> , <col2>…<colN>) SELECT  * FROM  <Backup Tablename> ;

Note : In case the backup table contains selective columns , then while copying data in the destination same columns should be specified.

Avatar photo

Shikha Katariya

Shikha

You may also like...