Wednesday 18 August 2010

Create table from existing table structure and insert data

Sometimes we might need to create a SQL table from an existing table and insert data from that particular table. So instead of creating the table separately using the ‘CREATE TABLE’ command, we can use the following statement.

Syntax:
select <FieldList> into new_table
from existing_table
<where condition>


Example:

select emp_id, emp_fname, emp_lname into emp_temp
from emp_master
where emp_state = 'NY'






** If  you created the table for temporary usage, make sure to drop it, after using it.

No comments:

Post a Comment