Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Definition:
Experiment:1 Date:
DDL statements are used to alter/modify a database or table structure and schema. Thes
handle the design and storage of database objects. The statements belonging to DDL ar
Syntax:
Syntax:
OUTPUT:
PROCEDURE:
1. Create a table named ‘student’ using the DDL command ‘create’ with the
following columns: register_no as int, name as varchar and subject as varchar.
2. Add an additional column ‘phone’ to the table using the DDL command ‘alter’.
RESULT:
The DDL commands for student database is executed and output is verified.
1. Definition:
Date:
Experiment:2
DML Commands
1.1 DML (Data Manipulation Language)
DML statements affect records in a table. These are basic operations we perform on data such
a few records from a table, inserting new records, deleting unnecessary records, and updatin
existing records. DML statements include the following:
(column-1,column-2,...column-n)
5.PROCEDURE:
1. Create a table named ‘student’ using the DDL command ‘create’ with the following columns: regis
name as varchar and subject as varchar. 2. Insert 5 rows into the table created using the ‘insert’ DML
with values corresponding to each column. 3. Using the DML command ‘select’, display the created t
an additional column ‘phone’ to the table using the DDL command ‘alter’. 5. Update the table using t
command ‘update’ giving appropriate conditions for it. 6. Using the DML command ‘select’, display
table. 7. Delete rows from the table using the DML command ‘delete’. 8. Using the DDL command ‘t
truncate the table. 9. Using the DDL command ‘drop’, drop the table. Program:
6.Create table student(id int,name varchar(10),subject varchar(20));
Values(1,’EZIO’,’COMPUTER');
Values(2,’EVIE’,’PHYSICS’);
Values(3,’EDEN’,’CHEMISTRY’);
Values(4,’ETHERAPE’,’CIVIL’);
Values(5,’EDGAR’,’Management’);
14.Update student
15.Update student
Set PHONE=’8754426950’
Where id=’1’;
16.Select * from student;
Where id=’4’;
RESULT:
The DML commands for student database is executed and output is verified.
Experiment:3 Date:
Select Distinct, And, Or, Order by Commands
Definition 1. SELECT DISTINCT:– The SELECT DISTINCT statement is used to
return only distinct (different) values. Syntax: SELECT DISTINCT
column1, column2, ... FROM table_name;
PROCEDURE:
1. Create a table named ‘student’ using the DDL command ‘create’ with the following columns: id as
varchar and subject as varchar. 2. Insert 10 rows into the table created using the ‘insert’ DML comma
corresponding to each column. 3. Using the DML command ‘select’, display the created table. 4. Use
Distinct, And, Or, Order by statements in the table. 5. Using the DML command ‘select’, display the
6. Using the DDL command ‘truncate’, truncate the table. 7. Using the DDL command ‘drop’, drop th
Program:
Experiment:4
DATE:
Aim:
SYNTAX:
SELECT column1, column2, ... FROM table_name WHERE condition1 AND condition2 AND condi
...;UPDATE – update/Modify existing records
OUTPUT:
Create table student(id int,name varchar(10),subject varchar(20)); insert into student
Values(1,’Arun’,’Math’);
The Select Distinct, And, Or and Order By commands for student database is executed and
verified.
Experiment:5 Date:
Constraints
Definition:
Constraints are the rules that we can apply on the type of data in a table. That is, we can sp
limit on the type of data that can be stored in a particular column in a table using constrain
constraints used are 1. NOT NULL: This constraint tells that we cannot store a null value i
column. That is, if a column is specified as NOT NULL then we will not be able to store n
particular column any more. 2. UNIQUE: This constraint when specified with a column, te
the values in the column must be unique. That is, the values in any row of a column must n
repeated. 3. PRIMARY KEY: A primary key is a field which can uniquely identify each ro
table. And this constraint is used to specify a field in a table as primary key. 4. FOREIGN
Foreign key is a field which can uniquely identify each row in a another table. And this co
used to specify a field as Foreign key. 5. CHECK: This constraint helps to validate the val
column to meet a particular condition. That is, it helps to ensure that the value stored in a c
meets a specific condition. 6. DEFAULT: This constraint specifies a default value for the c
when no value is specified by the user. Syntax for using these constraints
are 1.CREATE TABLE table_name ( column1 datatype constraint,
column2 datatype constraint, column3 datatype constraint, .... );
OUTPUT:
PROCEDURE:
1. Create a table named ‘CUSTOMER’ using the DDL command ‘create’ with the following columns
NULL Primary Key, firstname as varchar NOT NULL, lastname as varchar NOT NULL, salary int, p
DEFAULT ‘Bombay’and CHECK whether salary>=10000 2. Insert 5 rows into the table created usin
DML command with values corresponding to each column. 3. Using the DML command ‘select’, disp
created table. 4. Using the DDL command ‘truncate’, truncate the table. 5. Using the DDL command
the table.
Program: 1. create table CUSTOMER(cid int NOT NULL PRIMARY
KEY,firstname varchar(20) NOT NULL,lasttname varchar(20) NOT NULL,salary int,p
varchar(20) DEFAULT 'Bombay',check(salary>=10000)); 2. insert into CUSTOMER
values('1','Arun','Prasad','20000','chennai'); 3. insert into CUSTOMER
values('2','raghav','orton’,'68000','bangalore'); 4. insert into CUSTOMER
values('3','Vivek','choco','10000','goa'); 5. insert into CUSTOMER
values('4','shamin','kukku','60000','kerala'); 6. insert into CUSTOMER
values('5','prarthana','ravi','55000',DEFAULT); 7. select * from customer where
salary>25000; 8. select * from customers where place=’Bombay’;
RESULT:
The constraints for customer database and product database are applied, executed and outp
verified.
Experiment:6 Date:
Join Commands
1. Definition A JOIN clause is used to combine rows from two or more tables, based on a
column between them. Different types of Join are 1. Inner Join:-
Returns records that have matching values in both tables Syntax: SELECT column_nam
FROM table1 INNER JOIN table2 ON table1.column_name = table2.column_name;
Syntax:
5. Natural Join:
A Natural Join is a Join operation that creates an implicit join clause for you based on t
columns in the two tables being joined. Common columns are columns that have the sa
both tables. A Natural Join can be an Inner join, a Left Outer join, or a Right Outer join
default is Inner join. Syntax: TableExpression NATURAL [ { LEFT | RIGHT } [ OUTE
INNER ] JOIN { TableViewOrFunctionExpression | ( TableExpression ) }
RESULT:
The join statements for student and sports database are executed and output is verified.
Definition:
Date:
Experiment:7
Count: The Count function counts the number of cells that contain numbers, and cou
numbers within the list of arguments. Syntax: SELECT COUNT(column_name) FROM ta
WHERE condition;
PROGRAM:
1. create table student(id int primary key not null, name varchar(20), age
int, marks int); 2. insert into student values('1', 'Arun','21','80'); 3. insert into student
values('2', 'raghav','20','92'); 4. insert into student values('3', ‘vivek','21','95'); 5.
insert into student values('4', 'shamin','21','74'); 6. insert into student values('5',
'prarthana','19','75'); 7. select * from student; 8. select count(age) from student
where age>19;
RESULT:
The SQL functions for student database is executed and output is verified.
OUTPUT:
Subqueries
Date:
Experiment:8
Definition: A Subquery or Inner query or a Nested query is a query within another SQL qu
embedded within the WHERE clause. A subquery is used to return data that will be used i
query as a condition to further restrict the data to be retrieved. Subqueries can be used with
SELECT, INSERT, UPDATE, and DELETE statements. 1. Subqueries with the SELECT
Syntax is SELECT column_name [, column_name ] FROM table1 [,
table2 ] WHERE column_name OPERATOR (SELECT column_name
[, column_name ] FROM table1 [, table2 ] [WHERE])
[WHERE) ]
PROGRAM:
OUTPUT:
Experiment:9 Date:
Views
Definition: A view is a virtual table based on the result-set of an SQL statement. A view c
rows and columns, just like a real table. The fields in a view are fields from one or more re
in the database. Syntax: CREATE VIEW view_name AS SELECT column1, column2, ... FROM tabl
WHERE condition;
where salary>20000;
where salary>20000;
RESULT:The view commands for customer database are executed and output is verified.
OUTPUT:
DATE:
Aim: To execute the PL/SQL programs. Definition:PL/SQL stands for Procedural Language extensions to SQL.
extension of Structured Query Language (SQL) that allows the programmer to write code in a procedural format.
the data manipulation power of SQL with the processing power of procedural language to create super powerful
queries.Similar to other database languages, it gives more control to the programmers by the use of loops, condit
object-oriented concepts. Syntax: DECLARE
<declarations section> BEGIN
<executable command(s)> EXCEPTION
<exception handling> END; Program 1: To write a PL/SQL program for checking if the number is a palindrom
set serveroutput on
declare n number; m number; rev number:=0; r
number; begin n:=&n; m:=n; while n>0 loop
r:=mod(n,10); rev:=(rev*10)+r; n:=trunc(n/10);
OUTPUT:
greatest'); else
if b>a AND b>c then dbms_output.put_line('b is greatest'); else
declare
n number:=407; s number:=0; r number; len
number; m number;
begin
m:=n;
len:=length(to_char(n));
if m=s then
dbms_output.put_line('armstrong number'); else
dbms_output.put_line('not armstrong number'); end if;
end; / Result: The pl/Sql programs were successfully implemented and output verified succe
OUTPUT:
EXPIREMENT 11
PROCEDURES
EX.NO:
DATE:
Definition: The PL/SQL stored procedure or simply a procedure is a PL/SQL block which performs one or more
tasks. It is just like procedures in other programming languages.
Header: The header contains the name of the procedure and the parameters or variables passed to the proced
Body: The body contains a declaration section, execution section and exception section similar to a general
block.
Syntax:
[ (parameter [,parameter]) ]
IS
[declaration_section]
BEGIN
executable_section
[EXCEPTION
exception_section]
END [procedure_name];
DECLARE
a number;
b number;
c number;
BEGIN
IF x < y THEN
z:= x;
ELSE
z:= y;
END IF;
END;
BEGIN
a:= 23;
b:= 45;
findMin(a, b, c);
END;
OUTPUT:
Procedure 2 : procedure to find square of a number
DECLARE
a number;
BEGIN
x := x * x;
END;
BEGIN
a:= 23;
squareNum(a);
END;
OUTPUT:
EXPERIMENT 12
PL/SQL FUNCTIONS
EX.NO:12
DATE:
Definition: The PL/SQL Function is very similar to PL/SQL Procedure. The main difference between procedure
function is, a function must always return a value, and on the other hand a procedure may or may not return a val
this, all the other things of PL/SQL procedure are true for PL/SQL function too.
Syntax:
RETURN return_datatype
{IS | AS}
BEGIN
< function_body >
END [function_name];
DECLARE
a number;
b number;
c number;
RETURN number
IS z number;
BEGIN
IF x > y THEN
z:= x;
ELSE
Z:= y;
END IF;
RETURN z;
END;
BEGIN
a:= 23;
b:= 45;
c := findMax(a, b);
END;
/
RESULT: PL/SQL Functions are created successfully and output is verified successfully.
OUTPUT:
PL/SQL CURSORS
Ex No.13
Date:
Definition: A cursor is a temporary work area created in the system memory when a SQL
statement is executed. A cursor contains information on a select statement and the rows of
data accessed by it. This temporary work area is used to store the data retrieved from the
database, and manipulate this data. A cursor can hold more than one row, but can process
only one row at a time. The set of rows the cursor holds is called the active set.
DECLARE
total_rows number(2);
BEGIN
UPDATE customers
IF sql%notfound THEN
total_rows := sql%rowcount;
dbms_output.put_line( total_rows || ' customers selected ');
END IF;
END;
OUTPUT:
DECLARE
CURSOR cur_cus IS
SELECT name,
age,
address
FROM employees e
r_chief cur_chief%ROWTYPE;
BEGIN
OPEN cur_chief;
LOOP
r_chief.first_name || ',' ||
r_chief.last_name);
END LOOP;
CLOSE cur_chief;
END;
/ RESULT: The PL/SQL program to create cursors and implement in programs have been executed succe
Output 1:
Aim:
Experiment:14 Date:
Triggers
Definition:
<dml_trigger_option> ::=
[ NATIVE_COMPILATION ] [ SCHEMABINDING ] [
EXECUTE AS Clause ]
Program :
OUTPUT 2:
INSERT INTO LED_AUDIT
VALUES(:OLD.ACTIONDATE,:OLD.ITEM,:OLD.QUANTITY, :OLD:AMOUN
OUTPUT:
Trigger 3:
BEGIN
IF :OLD.AMOUNT>0 THEN
RAISE_APPLICATION_ERROR(-20001,’DELETION IS NOT
ALLOWED’)
END IF;
END;
Trigger 4:
BEGIN
END;
Experiment:15 Date:
Application Program
Aim:
Table information : Student table : Create table student(s_no int , reg no int , name
varchar(10), email varchar(20) ,mob no int , course varchar(7),subject
varchar(60));
Course table :
Program:
Table Creation:
Student table : Create table student(s_no int , reg no int , name varchar(10), email
varchar(20) ,mob no int , course varchar(7),subject varchar(60));
Course table :
Connection:
<?php
class Database {
private $_connection;
/*
@return Instance
*/
return self::$_instance;
}
// Constructor
// Error handling
if(mysqli_connect_error()) {
E_USER_ERROR);
return $this->_connection;
<?php
session_start ();
if (! (isset ( $_SESSION ['login'] ))) {
header ( 'location:../index.php' );
} include('../config/DbFunction.php');
$obj=new DbFunction();
$rs=$obj->showCourse();
$rs1=$obj->showCountry();
$ses=$obj->showSession();
$res1=$ses->fetch_object();
//$res1->session;
if(isset($_POST['submit'])){