CREATE TABLE
It is used to create new table structure.
syntax:CREATE TABLE table_name (column1,column2....);
Create Table By Subquery.
Syntax:CREATE TABLE table_name (column1,column2....) AS Subquery;
ALTER TABLE
It is uaed to add, modify, or drop columns.
syntax for ADD:ALTER TABLE table_name ADD (column datatype,column datatype....);
syntax for MODIFY:ALTER TABLE table_name MODIFY (column datatype,column datatype....);
syntax for DROP:ALTER TABLE table_name DROP (column);
DROP TABLE
All data and structure of table is deleted.
syntax:DROP TABLE table_name;
RENAME
It is used to change the name of a table, view, sequence, or synonym.
syntax:RENAME old_table_name TO new_table_name ;
TRUNCATE TABLE
It is remove all rows from a table and releases the storage space used by that table. we can not roll back row removal using trancate.
syntax:TRUNCATE TABLE table_name;
COMMENT
It is used to add comments to a table or column by using the COMMENT statement.
syntax:COMMENT ON TABLE table_name | COLUMN TABLE.column_name IS 'text';
For solving the above question we need to create two tables (EMPLOYEE , DEPARTMENT)
create table employee
(
empid number(5) primary key,
empname varchar2(50),
salary number(10,2),
Grade number(1),
deptno number(3) references department(deptno),
location varchar2(50),
desig varchar(20)
);
create table department
(
deptno number(3) primary key,
deptname varchar(50)
);
Then Insert few records in Employee and Department table.
EMPLOYEE
EMPID |
EMPNAME |
SALARY |
GRADE |
DEPTNO |
LOCATION |
DESIG |
1 |
AMIT SEN |
10000 |
1 |
1 |
BHOPAL |
MANAGER |
2 |
RAMESH THAKUR |
11000 |
2 |
1 |
BHOPAL |
CLERK |
3 |
RAKESH |
12000 |
1 |
1 |
INDORE |
CLERK |
4 |
SUMIT SAKET |
9000 |
3 |
2 |
BHOPAL |
CLERK |
5 |
AMIT SEN |
11000 |
2 |
2 |
BHOPAL |
MANAGER |
6 |
AMIT SEN |
12000 |
2 |
5 |
INDORE |
CLERK |
7 |
AMIT SEN |
15000 |
1 |
6 |
INDORE |
MANAGER |
DEPARTMENT
DEPTNO |
DEPTNAME |
1 |
SALES |
2 |
PRODUCTION |
3 |
PURCHASE |
4 |
MARKETING |
5 |
ACCOUNTS |
6 |
HR |
7 |
ADMIN |
No comments:
Post a Comment