Wa0000.
Wa0000.
EX.NO : 1
DATE :
AIM:
To execute the various Data Definition Language commands in RDBMS.
DATABASE:
1. Creation of database
Output:
+--------------------+
| Database |
+--------------------+
| information_schema |
| cs22187 |
| test |
+--------------------+
3 rows in set (0.01 sec)
3. Using of database
Output:
Database changed
TABLES:
5. Creation of table
Output:
+-------------------+
| Tables_in_cs22187 |
+-------------------+
| Employee |
| student |
| student1 |
+-------------------+
Output:
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| rno | int(3) | YES | | NULL | |
| name | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
Output:
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| rno | int(3) | YES | | NULL | |
| name | varchar(10) | YES | | NULL | |
| dept | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
Output:
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| rno | int(3) | YES | | NULL | |
| name | varchar(10) | YES | | NULL | |
| gpa | float | YES | | NULL | |
| dept | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
10. To rename a table
Syntax: alter table tbname rename new_name;
Output:
+-------------------+
| Tables_in_cs22187 |
+-------------------+
| Employee |
| student1 |
| student2 |
+-------------------+
Output:
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| rno | int(3) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| grade | float | YES | | NULL | |
| department | varchar(30) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
Output:
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| s_regno | int(5) | NO | PRI | NULL | |
| s_name | varchar(10) | YES | | NULL | |
| deptname | varchar(10) | YES | | NULL | |
| dob | date | YES | | NULL | |
| address | varchar(20) | YES | | NULL | |
| cgpa | float(5,2) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
13. To delete a table
Syntax: drop tbname;
Output:
Empty set (0.00 sec)
CONSTRAINTS:
RESULT:
The required data description language commands were executed and the output
was obtained successfully.
AIM:
To execute and verify the DML commands are the most frequently used SQL
commands and is used to query and manipulate the existing database objects.
Output:
Query OK, 5 rows affected (0.00 sec) Records: 5
Duplicates: 0 Warnings: 0
Output:
| +-------+---------+--------+---------+ |
| | empid | empname | empsal | empdept | |
| +-------+---------+--------+---------+ |
| 1 | Ram | 2000 | Accounts |
| 2 |Jaanu | 5000 | Accounts |
| 3 |Lamar | 7000 |Engineering |
| 4 |Alan | | 6000 | Hist |
| 5 |Wasim | 6000 | Accounts |
| +-------+---------+--------+---------+ |
5 rows in set (0.00 sec)
Output:
| +-------+---------+-----+ |
| empname | empsal |
| +-------+---------+-----+ |
| Ram | 2000 |
| Jaanu | 5000 |
| Sean | 7000 |
| Alan | | 6000 |
| Wasim | 6000 |
| | +-------+---------+-----+ |
5 rows in set (0.00 sec)
Output:
+---------+
| empdept |
+---------+
| Accounts |
| Engineering |
| Hist |
+---------+
3 rows in set (0.00 sec)
Output:
+-------+---------+
| empid | empname |
+-------+---------+
| 1 | Ram |
| 2 |Jaanu |
| 4 |Alan |
| 5 |Wasim |
| 3 |Sean |
+-------+---------+
5 rows in set (0.00 sec)
Output:
+---------+
| empname |
+---------+
| Alan |
+---------+
1 row in set (0.00 sec)
Output:
+---------+
| empname |
+---------+
| Alan |
| Wasim |
+---------+
2 rows in set (0.00 sec)
Output:
| +-------+---------+--------+---------+ |
| | empid | empname | empsal | empdept | |
| +-------+---------+--------+---------+ |
| 1 | Ram | 2000 | Accounts |
| 2 |Jaanu | 5000 | Accounts |
| 3 |Sean | 7000 |Engineering |
| 4 |Alan | | 6000 | Hist |
| 5 |Wasim | 6000 | Accounts |
| 0 |Carl | NULL | NULL |
| +-------+---------+--------+---------+ |
5 rows in set (0.00 sec)
Output:
| +-------+---------+--------+---------+ |
| | empid | empname | empsal | empdept | |
| +-------+---------+--------+---------+ |
| 1 | Ram | 2000 | Accounts |
| 2 |Jaanu | 5000 | Accounts |
| 3 |Sean | 7000 |Engineering |
| 4 |Alan | | 6000 | Hist |
| 5 |Wasim | 6000 | Accounts |
| +-------+---------+--------+---------+ |
5 rows in set (0.00 sec)
Output:
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| empid | int(2) | NO | |0 | |
| empname | varchar(10) | YES | | NULL | |
| empsal | float | YES | | NULL | |
| empdept | varchar(10) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
RESULT:
The required data manipulation language commands were successfully executed.
AIM:
To performing insertion, deletion, modifying, altering, updating and viewing records
based on conditions.
1. CREATE TABLE
create table employee(empno int(10),ename varchar(20), job varchar(10),mgr int(10),
hiredate date, sal int(10),deptno int(10));
Query OK, 0 rows affected, 4 warnings (0.03 sec)
desc employee;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| empno | int | YES | | NULL | |
| ename | varchar(10) | YES | | NULL | |
| job | varchar(20) | YES | | NULL | |
| mgr | int | YES | | NULL | |
| hiredate | date | YES | | NULL | |
| sal | int | YES | | NULL | |
| deptno | int | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
2. INSERT VALUES
insert into employee values
(7370,"Allen","Salesman",5002,"1908-02-03",3000,300),
(7521,"Jones","Salesman",5003,"1980-03-13",5000,500),
(7566,"Dennis","Manager",5002,"1985-03-26",75000,200),
(7576,"Raja","Owner",5000,"1982-09-25",9000,900),
(7586,"Benny","COE",5001,"1984-03-30",8000,800),
(7499,"Henry","CEO",5005,"1987-03-30",50000,500);
Query OK, 6 rows affected (0.04 sec)
Records: 6 Duplicates: 0 Warnings: 0
5. RELATIONAL OPERATOR
6. AND / OR
7. ORDER BY
8. ALTER
a) ADDING COLUMN
alter table employee add tax int;
Query OK, 0 rows affected (0.07 sec)
Records: 0 Duplicates: 0 Warnings: 0
desc employee;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| empno | int | YES | | NULL | |
| job | varchar(10) | YES | | NULL | |
| ename | varchar(20) | YES | | NULL | |
| mgr | int | YES | | NULL | |
| hiredate | date | YES | | NULL | |
| sal | int | YES | | NULL | |
| deptno | int | YES | | NULL | |
| TAX | int | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
10. rows in set (0.00 sec)
DESC EMPLOYEE;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| empno | int | YES | | NULL | |
| job | varchar(10) | YES | | NULL | |
| ename | varchar(20) | YES | | NULL | |
| mgr | int | YES | | NULL | |
| hiredate | date | YES | | NULL | |
| sal | int | YES | | NULL | |
| deptno | int | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
10 rows in set (0.00 sec)
C) RENAMING
DESC EMPLOYEE;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| empno | int | YES | | NULL | |
| job | varchar(10) | YES | | NULL | |
| ename | varchar(20) | YES | | NULL | |
| mgr | int | YES | | NULL | |
| hiredate | date | YES | | NULL | |
| SALARY | int | YES | | NULL | |
| deptno | int | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
7 rows in set (0.00 sec)
9. USING UPDATE
RESULT:
Thus the SQL commands for Performing Insertion, Deletion, Modifying, Altering, Updating
and Viewing records based on conditions has been verified and executed successfully.
AIM:
To create views, synonyms, sequences, indexes and save points using DDL, DML and DCL
statements.
create table fviews( name varchar(20),no int(5), sal int(5), dno int(5));
Query OK, 0 rows affected, 3 warnings (0.07 sec)
create view ssview( cusname,id) as select name, no from fviews where dno=12;
Query OK, 0 rows affected (0.04 sec)
Create synonym:
NAME ID
---------- ----------
anu 1
brindha 2
chinthiya 3
divya 4
ezhil 5
fairoz 7
hema 9
kalai 20
8 rows selected.
NAME ID
---------- ----------
anu 1
brindha 2
chinthiya 3
divya 4
ezhil 5
fairoz 7
hema 9
kalai 20
8 rows selected.
NAME ID
---------- ----------
anu 1
brindha 2
chinthiya 3
divya 4
ezhil 5
fairoz 7
hema 9
kalai 20
Manu 21
9 rows selected.
Drop Synonym:
drop synonym c1;
Synonym dropped.
select * from c1;
ERROR at line 1:
ORA-00942: table or view does not exist
Sequences
Creation of table:
Create Sequence:
create sequence s_1
2 start with 4
3 increment by 1
4 maxvalue 100
5 cycle;
Sequence created.
insert into class values('divya',s_1.nextval);
1 row created.
select * from class;
NAME ID
---------- ----------
anu 1
brindha 2
chinthiya 3
divya 4
Alter Sequence:
alter sequence s_1 increment by 2;
Sequence altered.
insert into class values('fairoz',s_1.nextval);
1 row created.
NAME ID
---------- ----------
anu 1
brindha 2
chinthiya 3
divya 4
ezhil 5
fairoz 7
Drop Sequence:
drop sequence s_1;
Sequence dropped.
Indexes:
DCL statements
COMMIT, ROLLBACK and SAVEPOINT:
commit;
Query OK, 0 rows affected (0.00 sec)
savepoint A;
Query OK, 0 rows affected (0.00 sec)
savepoint B;
Query OK, 0 rows affected (0.00 sec)
rollback to B;
Rollback complete.
select * from class;
+----------+------+
| name | id |
+----------+------+
| radha | 101 |
| krishna | 102 |
| shiv | 103 |
| parvathi | 104 |
| hema | 9 |
| indu | 11 |
+----------+------+
6 rows in set (0.00 sec)
rollback to A;
Rollback complete.
select * from class;
+----------+------+
| name | id |
+----------+------+
| radha | 101 |
| krishna | 102 |
| shiv | 103 |
| parvathi | 104 |
| hema | 9 |
+----------+------+
6 rows in set (0.00 sec)
RESULT:
Thus the Views, Synonyms, and Sequences, indexes and save points has been
executed using DDL, DML and DCL statements.
AIM:
To study the various constraints available in the SQL query language.
create table employe(ename varchar(30) not null, eid varchar(20) not null);
Query OK, 0 rows affected (0.06 sec)
create table depts ( dname varchar(30) not null, did int(20) not null check (did<10000));
Query OK, 0 rows affected, 1 warning (0.06 sec)
create table book (bname varchar(30) not null, bid int(20) not null unique);
Query OK, 0 rows affected, 1 warning (0.05 sec)
create table orders( oname varchar(30) not null , oid int(20) not null , unique(oname,oid));
Query OK, 0 rows affected, 1 warning (0.06 sec)
create table custo ( cname varchar(30) not null , cid int(20) not null primary key);
Query OK, 0 rows affected, 1 warning (0.05 sec)
create table branches( bname varchar(30) not null , bid int(20) not null , primary
key(bname,bid));
Query OK, 0 rows affected, 1 warning (0.06 sec)
ALTER TABLE
alter table semp add(eddress varchar(20));
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0
RESULT
The various constraints were implemented and the tables were created using the
respective constraints.