DDL commands are used to define the data base objects.The following commands are
used to define data base objects.
1. create
2. alter
3. truncate
4. rename
5. drop
1. create
create command defines a new database object, such as a database, user, table,
view, trigger, index, macro, stored procedure, user-defined type, user-defined
function, or user-defined macro, depending on the object of the CREATE request.
Syntax :
ALTER statement to add a column, modify a column, drop a column, rename a column or
rename a table.
Syntax of Single Column Adding:
Note : We can�t modify any column if table contains data means if you want to
increase range of data then table should be empty.
Syntax of drop a column in an existing table :
3. truncate
By using this command , we can delete data of the table but definition of the
object will remain same.
Syntax :
Example :
5. drop
Syntax :
Example :
Answer : xx_dept table will be create same as dept except constraints,here not null
will be applicable.
Answer : xx_dept table will be create same as dept except constraints,here not null
will be applicable.
Answer : xx_dept table will be create same as dept with structure only.
Data Retrieval or Query Language(DQL or DRL) :
here SELECT clause will come under this category,main usage of select to identify
the result set column list.
Syntax :
select *
from table_name;
select column1,column2�
from table_name;
Example :
select *from
dept;
this statement will fetch all columns of dept table.but it is not suggestible
approach.
select deptno,
dname,
loc
from dept;
These statements are used to manage the data with database objects.
Categorization of Commands :
INSERT :
insert data into a table :
Syntax :
Example 1 :
Example 2:
INSERT INTO EMP VALUES
(7369, �SMITH�, �CLERK�, 7902,
TO_DATE(�17-DEC-1980', �DD-MON-YYYY�), 800, NULL, 20);
INSERT INTO EMP VALUES
(7499, �ALLEN�, �SALESMAN�, 7698,
TO_DATE(�20-FEB-1981', �DD-MON-YYYY�), 1600, 300, 30);
INSERT INTO EMP VALUES
(7521, �WARD�, �SALESMAN�, 7698,
TO_DATE(�22-FEB-1981', �DD-MON-YYYY�), 1250, 500, 30);
INSERT INTO EMP VALUES
(7566, �JONES�, �MANAGER�, 7839,
TO_DATE(�2-APR-1981�, �DD-MON-YYYY�), 2975, NULL, 20);
INSERT INTO EMP VALUES
(7654, �MARTIN�, �SALESMAN�, 7698,
TO_DATE(�28-SEP-1981', �DD-MON-YYYY�), 1250, 1400, 30);
INSERT INTO EMP VALUES
(7698, �BLAKE�, �MANAGER�, 7839,
TO_DATE(�1-MAY-1981�, �DD-MON-YYYY�), 2850, NULL, 30);
INSERT INTO EMP VALUES
(7782, �CLARK�, �MANAGER�, 7839,
TO_DATE(�9-JUN-1981�, �DD-MON-YYYY�), 2450, NULL, 10);
INSERT INTO EMP VALUES
(7788, �SCOTT�, �ANALYST�, 7566,
TO_DATE(�09-DEC-1982', �DD-MON-YYYY�), 3000, NULL, 20);
INSERT INTO EMP VALUES
(7839, �KING�, �PRESIDENT�, NULL,
TO_DATE(�17-NOV-1981', �DD-MON-YYYY�), 5000, NULL, 10);
INSERT INTO EMP VALUES
(7844, �TURNER�, �SALESMAN�, 7698,
TO_DATE(�8-SEP-1981�, �DD-MON-YYYY�), 1500, 0, 30);
INSERT INTO EMP VALUES
(7876, �ADAMS�, �CLERK�, 7788,
TO_DATE(�12-JAN-1983', �DD-MON-YYYY�), 1100, NULL, 20);
INSERT INTO EMP VALUES
(7900, �JAMES�, �CLERK�, 7698,
TO_DATE(�3-DEC-1981�, �DD-MON-YYYY�), 950, NULL, 30);
INSERT INTO EMP VALUES
(7902, �FORD�, �ANALYST�, 7566,
TO_DATE(�3-DEC-1981�, �DD-MON-YYYY�), 3000, NULL, 20);
INSERT INTO EMP VALUES
(7934, �MILLER�, �CLERK�, 7782,
TO_DATE(�23-JAN-1982', �DD-MON-YYYY�), 1300, NULL, 10);
Important Note :
We can Insert data by using select statement also.
Example :
first create table without data.
But here it will insert only specified columns for deptno 10 only.
UPDATE :
updates existing data within a table.
Syntax :
UPDATE <table_name>
SET <column_name> = <value>
WHERE <column_name> = <value>;
Examples:
update emp
set sal=sal+2000;
it will update all records of emp,but it�s suggestible way in real time, surely
updation can be done based on some condition.
update emp
set sal=sal+2000
where empno=7788;
update emp
set sal=sal+2000,
job=�Manager�
where empno=7788;
DELETE :
deletes all records from a table :
Syntax :
delete
from table_name
where <column_name>=<value>;
Examples:
delete
from emp
where deptno=10;
Note : We can�t delete specific column from table, like the following way.
delete empno
from emp;
MERGE :
Primary usage merge when moving large amounts of data from one table to another
table.this kind work can be done in data warehouse.
Example :
SQL GRANT is a command used to provide access or privileges on the database objects
to the users.
GRANT :
gives user�s access privileges to database.
GRANT privilege_name
ON object_name
TO {user_name |PUBLIC |role_name}
[WITH GRANT OPTION];
Examples:
grant select on
emp to scott;
grant select,insert,delete on
emp to scott;
REVOKE :
withdraw access privileges given with the GRANT command.
REVOKE privilege_name
ON object_name
FROM {user_name |PUBLIC |role_name} ;
Example :
revoke insert, delete on
emp from scott;
Transaction Control Language(TCL) :
TCL statements used to manage the changes made by DML statements. It allows
statements to be grouped together into logical transactions.
COMMIT :
permanent save to work done.here we can�t roll back once applied commit.
Example :
COMMIT;
SAVEPOINT :
identify a point in a transaction and which you can later roll back also.
Example :
ROLLBACK :
restore database to original since the last COMMIT
Example :
ROLLBACK;