Ex - No: 1 (A) SQL Commands: DDL Commands: (Data Definition Language)
Ex - No: 1 (A) SQL Commands: DDL Commands: (Data Definition Language)
DDL commands are used to create an object, alter the structure of an object and also drop the
object created.
CREATE Command:
This command is used to create a table or an object.
Syntax: create table <tablename>(<column name1> datatype, <column name2 > datatype,....);
ALTER Command:
This command is used to add a field or modify the definition of field or column.
Syntax:
alter table <tablename> add (<column name1> datatype, <column name2> datatype, .....);
alter table <tablename> modify (<column name1> datatype, <column name2> datatype, ...);
TRUNCATE Command:
This command is used to delete all the rows of a table but not the structure of the table.
Syntax: truncate table <tablename>;
DROP Command:
This command is used to delete the entire table along with the structure.
Syntax: drop table <tablename>;
Note:
i) DESC Command:
This command is used to describe the table structure.( field or column name, datatype, null?)
Syntax: desc <table name>
ii) Data types:
char, varchar(size),varchar2(size),date,number,number(size)
date –default format – dd/mon/yy (Eg. 27-jan-78)
iii) ORACLE implicitly commits the current transaction before and after every Data Definition
Language statement.
DML Commands:( Data Manipulation Language)
DML commands are used to insert, view, update and delete the values of an object.
INSERT Command:
This command is used to insert a set of data values into the tables as defined in the create
table command.
Syntax:
insert into <tablename>values (value1,value2,.....,valuen);
insert into <table name> values(&columnname1,&columnname2,.....,&columnname n);
Note: varchar type field or column must be enclosed within single quotes.Eg.’&column’
SELECT Command:
This command is used to view particular data records or columns.
Syntax:
select <column name1,....>from <tablename>;
select * from <tablename>; - to view all records.
select distinct <columnname> from <tablename>;
select * from <tablename> orderby <columnname>; - default –ascending order.
select * from <tablename> orderby <columnname> desc;
- Records are sorted in descending order w.r.t column name
select * from <tablename> where <condition>;
UPDATE Command:
This command is used to update and change the data values of the table.
Syntax:
update <tablename> set <column>=value where <condition>;
DELETE Command:
This command is used to delete a particular record or all records of the table.
Syntax:
delete from <tablename> where <condition>;
delete * from <tablename>; -- to delete all the records or rows of a table.
-- similar to truncate command.
IMPLEMENTATION OF SQL COMMANDS(DDL &DML):
SQL> create table Tel(name varchar2(10),telno number(7));
Table created.
SQL> desc tel;
Name Null? Type
----------------------------------------- -------- ----------------------------
NAME VARCHAR2(10)
TELNO NUMBER(7)
SQL> /
Enter value for name: Sankar
Enter value for telno: 2330289
Enter value for city: Tvl
old 1: insert into tel values('&name',&telno,'&city')
new 1: insert into tel values('Sankar',2330289,'Tvl')
1 row created.
SQL> /
Enter value for name: Banu
old 1: select * from tel where name='&name'
new 1: select * from tel where name='Banu'
1 row updated.
1 row updated.
1 row deleted.
Table truncated.
no rows selected
Table dropped.
RESULT:
Thus the Data Definition Language and Data Manipulation Language commands are
implemented in ORACLE with database tables.