Class-8 (CTAS, INSERT ALL, ALTER Command)
Class-8 (CTAS, INSERT ALL, ALTER Command)
-------------
CTAS:(Create Table As Select)
------------------------------
> Using this method , we can create a new table based on the existing table
Create a new table which will copy the structure(not data) of the existing table
----------------------------------------------------------------------------------
Syntax
------
CREATE TABLE <Table Name> AS <Select Statement > and a <False Condition>
Create a new table which will copy the structure and data of the existing table
----------------------------------------------------------------------------------
Syntax
------
CREATE TABLE <Table Name> AS <Select Statement >
INSERT ALL
----------
> Using this command , we can insert multiple records into a table at a time
> It also inserts multiple records into multiple tables
Syntax
------
INSERT ALL
INTO <Table Name>(<Col 1>,<Col 2>,..,<Col n>) VALUES (<Val 1>,<Val 2>,...,<Val n>)
INTO <Table Name>(<Col 1>,<Col 2>,..,<Col n>) VALUES (<Val 1>,<Val 2>,...,<Val n>)
.....
INTO <Table Name>(<Col 1>,<Col 2>,..,<Col n>) VALUES (<Val 1>,<Val 2>,...,<Val n>)
SELECT * FROM DUAL;
INSERT ALL
INTO STUDENTS(ROLL_NO,SNAME,AGE) VALUES (1004,'Debendra',25)
INTO STUDENTS(ROLL_NO,SNAME,AGE) VALUES (1005,'Bikash',24)
INTO STUDENTS(ROLL_NO,SNAME,AGE) VALUES (1006,'Binaya',28)
SELECT * FROM DUAL;
--3 rows inserted.
COMMIT;
ALTER
-----
> It is used to change the structure of an existing table
OPerations of Alter command
----------------------------
(1) Adding a New column (Single/Multiple)
(2) Removing an Existing column (Single/Multiple)
(3) Modifing the size of a column (Single/Multiple)
(4) Modifing the data type of a Column (Single/Multiple)
(5) Renaming a column of a table (Single)
(6) Adding new constraint for a column
(7) Removing existing constraint
(8) Disabling Constraint
(9) Enabling Constraint
DESC STUDENTS;
O/P
---
Name Null? Type
-------- -------- ------------
ROLL_NO NOT NULL NUMBER(4)
SNAME NOT NULL VARCHAR2(30)
AGE NUMBER
GENDER CHAR(1)
MOB_NO VARCHAR2(13)
EMAIL_ID VARCHAR2(30)
DESC STUDENTS;
O/P
---
Name Null? Type
-------- -------- ------------
ROLL_NO NOT NULL NUMBER(4)
SNAME NOT NULL VARCHAR2(30)
AGE NUMBER
GENDER CHAR(1)
MOB_NO VARCHAR2(13)
DESC STUDENTS;
O/P
---
Name Null? Type
-------- -------- ------------
ROLL_NO NOT NULL NUMBER(4)
SNAME NOT NULL VARCHAR2(30)
AGE NUMBER
Syntax
------
ALTER TABLE <Table Name> MODIFY(<Col Name 1> <Data Type> (<Size>),
<Col Name 2> <Data Type> (<Size>),
.................................,
<Col Name n> <Data Type> (<Size>)
)
DESC STUDENTS;
O/P
---
Name Null? Type
------- -------- ------------
ROLL_NO NOT NULL NUMBER(4)
SNAME NOT NULL VARCHAR2(35)
AGE NUMBER