Record 1-4
Record 1-4
DATE:
AIM:
To create a database and write SQL quaries information from the
database.
DESCRIPTION:
DDL (data definition language) statement are used to
create ,changes the objects of the database. Typically a database
administrator is responsible for using DDL statement or production
database in a large data base system. The commands used are:
Create-it is used to create the table .
Alter- this command is used to add a new column, modify the existing
column definition and to include or drop integrity constraints
Drop- it will delete the table structure provided the table should empty.
Truncate-if there is no further use of records stored in the table and the
structure has to be retained and them the records alone can be deleted
Desc- this is used to view the structure of the table.
PROCEDURE:
step1:create table by using create table command with command
name,data type and size
step2:display the table by using desc command.
step3:add any new column with the exisiting by later command.
step4:modify the exisiting table with modify command.
CREATE TABLE:
SYNTAX:
CREATE Table tablename
(column_name1datatype(size),column_namedatatype(size),…..);
EXAMPLE:
SQL>CREATE Table student(studname char(20),studid varchar2(10),studdept
varchar2(20),studage number(5));
Table created
SQL>desc student;
Name NULL? TYPE
STUDNAME CHAR(20)
STUDID VARCHAR(10)
STUDDEPT VARCHAR(20)
STUDAGE NUMNER(5)
ALTER TABLE:
SYNTAX:
ALTER Table tablename add (column_name datatype(size));
ALTER Table tablename modify(column_name datatype(size));
ALTER Table tablename drop(column_name);
EXAMPLE:
SQL>ALTER table student add(stud_addr varchar2(20));
Table altered
SQL>desc student;
TRUNCAQTE TABLE:
SYNTAX:
TRUNCATE Table tablename;
EXAMPLE:
SQL>TRUNCATE Table student;
Tabel truncate
SQL>desc student;
Name NULL? TYPE
STUDNAME CHAR(20)
STUDID VARCHAR(10)
STUDDEPT VARCHAR(20)
STUDAGE NUMBER(10)
STUD_ARRD NUMBER(10)
RENAME:
SYNTAX:
RENAME OLD_TABLE_NAME TO NEW _TABLE_NAME;
EXAMPLE:
SQL>RENAME student to student1;
Table altered
SQL>desc student1;
Name NULL? TYPE
STUDNAME CHAR(20)
STUDID VARCHAR(10)
STUDDEPT VARCHAR(20)
STUDAGE NUMBER(10)
STUD_ADDR VARCHAR(20)
DROP TABLE:
SYNTAX:
DROP TABLE TABLE_NAME;
EXAMPLE:
SQL>DROP TABLE student1;
Table dropped
SQL>desc student1;
ERROR:ORA-04043:OBJECT STUDENT1 DOES NOT ACCESS.
DML COMMANDS
AIM:
To study and practice insertion,deletion,modifying,altered,
Updating and viewing records based on condition in RDBMS.
DESCRIPTION:
Data Manipulation Language:
DML comments are the most frequently used sql commands and is used to
query and manipulate the existing database objects. Some of the comments are
Insert
Select
Update
Delete
PROCEDURE:
STEP1:Create table by using create table command.
STEP2:Insert values into the table.
STEP3:Delete any records from the table.
STEP4:Update any values in the table.
STEP5:Display the values from the table by using select command.
SQL>create table student(studname char(20),studid varchar2(10),studdept
varchar2(20),studage number(5));
Table created.
SQL>desc Student;
Name NULL? TYPE
STUDNAME CHAR(20)
STUDID VARCHAR(10)
STUDDEPT VARCHAR(20)
STUD_AGE NUMBER(5)
INSERT:
This is used to add one or more rows to a table. The values are
separated by commas and the data types char and a data are enclosed in
apostrophes. The values must be in the same order as they are defined.
SYNTAX:
Insert into tablename values(‘&column_name1’,’&column_name2’,…….);
SQL>Insert intpo student1 values(‘&studname’,’&studid’,’&studdept’,’&stud_age’);
Insert into student1 values(‘ram’,’101’,’mech’,’104’)
1 row created.
Insert into student1 values(‘vicky’,’102’,’eee’,’105’)
1 row created
Insert into students values(‘saddiq’,’102’,’cse’,’101’)
1 row created
Insert into student1 values(‘David ‘,’104’,’eee’,’103’)
1 row created.
SELECT COMMAND:
It is used to retrive information from the table.it is generally reffered
to as querying table. We can either display all columns in a table or only
specify column from the table.
SYNTAX:
Select * from table_name;
Example:
SQL>select * from student1;
RESULT:
THUS, the inserting,deleting,modifiying,alternating,updating and
viewing records based on conditions using sql commands were executed
and verified successfully.
AIM:
To create the set of tables ,add foreign keys and incorporate the
referencial integrity.
FOREIGN KEY:
1)the foreign key is the type of the that refers to the primary key of
the another table.
2)the table which has the primary key is called as the parent table.
3)the table which has the foreign key is called as the child table.
SYNTAX:
FOREIGN KEY(attribute) REFERENCES TABLE_NAME(attribute);
CSE 101
ECE 105
EEE 109
SQL>/
Enter the value of studentname:seetha
Enter the value of sid:105
Enter the value of sphone:9865546774
Old 1:insert into student(‘&studentname’,’&sid’,’&sphone’);
New 1:insert into student(‘seetha’,’105’,’9865546774’)
1 row created
SQL>/
Enter the value of studentname:roja
Enter the value of sid:100
Enter the value of sphone:9577878885
ERROR: the value of sid is not found in parent key
SQL>SELECT * from student;
STUDENTNAME SID SPHONE
RESULT:
Thus the set of tables were created,foreign keys added and referencial
Integrity was incorporated.
EX.NO:3 QUERY THE DATABASE TABLES USING DIFFERENT
DATE: ‘WHERE’ CLAUSE CONDITIONS AND ALSO
IMPLEMENT AGGREGATION FUNCTIONS.
AIM:
To Query the database tables using different ‘where’clause condition and also
implement aggregation function.
WHERE CLAUSE:
The where clause is used to filter the tuples from the database tables.
SYNTAX:
SELECT col1,col2,…coln from table_name WHERE condition;
QUERY:CREATING TABLE:
SQL>CREATE Table demo(studentnamevarchar(80),sid integer,mark1 integer,mark2
Integer,mark3 integer);
Table created.
SQL>INSERT into demo values
(‘&studentname’,’&sid’,’&mark1’,’&mark2’,’&mark3’);
Enter value for studentname:ram
Entyer value for sid:101
Enter value for mark1:88
Enter value for mark2:90
Enter value fro mark3:98
Old 1:insert into demo
Values(‘&studentname’,’&sid’,’mark1’,’mark2’,’mark3’)
Min(mark1)
88
SQL>select max(mark1) from demo;
Max(mark1)
89
SQL>select avg(mark1) from demo;
AVG(MARK1)
88.75
SQL>select sum(mark1) from demo;
SUM(MARK1)
355
SQL>select count(mark1) from demo;
COUNT(MARK1)
4
RESULT:
Thus the where clause conditions and the aggregate function were
implemented successfully.
EX.NO:4 QUERY THE DATABASE TABLES AND EXPLORE SUB QUERIES
DATE: AND SIMPLE JOIN OPERTIONS
AIM:
To query the database tables and explore sun queries and simple join
operations.
SUBQUERIES:
The queries which as defined inside the another query is known as the
sub-queries. It is known as the nested queries.
There are two types of sub queries they are
Correlated
Non-correlated sub queries
SYNTAX:
SELECT columns from table where (…(select columns from table
where condition)…);
QUERY :THE QUERY TO FIND HIGNEST SALARYB FROM THE EMPLOYEE
TABLE
SQL>create table subquery(ename varchar(20),salary integer,eid integer);
Table created.
SQL>SELECT MAX(salary) from subquery;
MAX(SALARY)
RESULT:
Thus the various sub queries were implemented and the
join operations were performed successfully and output was
verified.