This statement is used to create a new fresh table from one/more existing table’s data/records by copying the columns/fields of the existing table partially or fully as needed.
Syntax :
(i) CREATETABLE new_table_name
AS (SELECT * FROM old_table_name);
(ii) CREATETABLE new_table_name
AS (SELECT * FROM old_table_name where condition);
(iii) CREATETABLE new_table_name
AS (SELECT column_name1, column_name2, column_name3, column_name4, column_name5 FROM old_table_name);
(iv) CREATETABLE new_table_name
AS (SELECT column_name1, column_name2, column_name3, column_name4, column_name5 FROM old_table_name);
(v) CREATETABLE new_table_name
AS (SELECT column_name1, column_name2, … column_name_nFROM old_table_name1, old_table_name2, … old_table_nameN);
Example :
(i) To display the structure details (metadata) of a table in SQL, including column names, types, and nullable constraints.
DESCRIBE employee;
(ii) To display the stored/added records or data of the created table in Oracle.
(a) To display all added or stored records
SELECT*FROM employee;
(b) To display selected/customized added or stored records
SELECT employee_id, first_name, salary FROM employee;
(iii) To create a table from an existing table
CREATETABLE employeeB
AS (SELECT * FROM employeeA WHERE emp_id = “50B3”);
(iv) To create a table from an existing table
CREATETABLE employeeB
AS (SELECT emp_id, emp_name, emp_addr, emp_dept, emp_sal FROM employeeA WHERE emp_id = “50B3”);
Introduction of TCL Statements TCL statements play a crucial role in managing transactions in a DBMS, providing mechanisms to ensure data integrity and consistency. Definition In a Database Management System (DBMS), Transaction Control Language (TCL) statements Read more…
Introduction SQL stands for ‘Structured Query Language’. SQL is pronounced as ‘Sequel’. SQL statements are like simple English imperative sentence. Features SQL is a query language used to retrieve and manipulate data in various ways as per Read more…
Currently Used SQL Keywords NB : SQL Keywords can be used as Identifiers in our query by putting them inside big bracket such as [ADD], [PERCENT], [ALL] etc. Read more…
0 Comments