SQL Backup query with where statement

SQL Backup query with where statement is used to construct a backup table using where clause.

SQL Backup query with where statement

SQL Backup query with where statement

     

SQL Backup query with where statement  is used to construct a backup table using where clause. The Where Clause in Backup query return you the restricted records into stu_tab_ Backup specified in table 'Stu_Table'.

Understand with Example

The Tutorial show you a example from 'SQL Backup query with where statement'. In order to understand this example, we create a table 'Stu_Table'. The create table is used to create a table 'Stu_Table'.  

Create Table Stu_Table

Create Table Stu_Table( Stu_Id int, Stu_Name varchar(15),Stu_Class());

Insert Data Into Stu_Table

Insert into statement add the records or rows to the table 'Stu_Table'.

insert into stu_table values(1, 'Komal',10);
insert into stu_table values(2, 'Ajay',10);
insert into stu_table values(3, 'Santosh',10);
insert into stu_table values(4, 'Rakesh',10);
insert into stu_table values(5, 'Bhau',10);
insert into stu_table values(1, 'aaa',11);
insert into stu_table values(2, 'bbb',11);
insert into stu_table values(3, 'ccc',11);
insert into stu_table values(4, 'ddd',11);
insert into stu_table values(5, 'eee',11);
insert into stu_table values(1, 'iii',12);
insert into stu_table values(2, 'jjj',12);
insert into stu_table values(3, 'kkk',12);
insert into stu_table values(4, 'lll',12);
insert into stu_table values(5, 'mmm',12);

Stu_Table

+--------+----------+-----------+
| Stu_Id | Stu_Name | Stu_Class |
+--------+----------+-----------+
| 1      | Komal    | 10        |
| 2      | Ajay     | 10        |
| 3      | Santosh  | 10        |
| 4      | Rakesh   | 10        |
| 5      | Bhau     | 10        |
| 1      | aaa      | 11        |
| 2      | bbb      | 11        |
| 3      | ccc      | 11        |
| 4      | ddd      | 11        |
| 5      | eee      | 11        |
| 1      | iii      | 12        |
| 2      | jjj      | 12        |
| 3      | kkk      | 12        |
| 4      | lll      | 12        |
| 5      | mmm      | 12        |
+--------+----------+-----------+

Backup Query

The Backup Query create a table 'stu_table_10_backup',This Backup table copies the records from table'stu_table' where field attribute 'stu_class" is equal to '10'.

create table stu_table_10_backup( select * from stu_table where stu_class=10);

Stu_Table_Backup

+--------+----------+-----------+
| Stu_Id | Stu_Name | Stu_Class |
+--------+----------+-----------+
| 1      | Komal    | 10        |
| 2      | Ajay     | 10        |
| 3      | Santosh  | 10        |
| 4      | Rakesh   | 10        |
| 5      | Bhau     | 10        |
+--------+----------+-----------+