What is the SQL SELECT INTO Statement and how it can be used with the database?
The SQL Select into statemet is used to take back of tables.
SQL SELECT INTO Statement Example:
Assume that you have a table 'customer' in your database. It has following columns: id, name, address, email and phone.
|1||Jwalant||123 xyz firstname.lastname@example.org||123-456-7890|
|2||Piyush||456 abc email@example.com||123-456-7890|
|3||Hiren||789 pqr firstname.lastname@example.org||123-456-7890|
Scenario 1: You want to take backup of this table and save it as customer_backup. Use following syntax of selecte sql into statement for that scenario:
SELECT * INTO customer_backup FROM customer;
Scenario 2: Instead of all coulmns, you want to get backup for only few columns. Use following syntax of sql select into statement for this scenario:
SELECT name, address, email INTO customer_backup FROM customer;
Scenario 3(SELECT INTO with IN clause): Instead of taking backup on the same database, you want to get backup on a different database. Use following syntax of sql select into statement with IN clause for this scenario:
SELECT * INTO customer_backup IN 'backup.customer' FROM customer;