student record
student record
AIM
PROCEDURE
List of DDL commands:
• CREATE: This command is used to create the database or its objects (like table, index,
function, views, store procedure, and triggers).
• DROP: This command is used to delete objects from the database.
• ALTER: This is used to alter the structure of the database.
• TRUNCATE: This is used to remove all records from a table, including all spaces
• RENAME: This is used to rename an object existing in the database.
2. SQL CREATE command It is used to create a new table in the database.
Syntax:
CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[,. ..]);
Or
Create table "table_name" ("column1" "data type", "column2" "data type", "column3" "data type",..
"columnN" "data type");
Example creates a table called "Persons" that contains five columns: PersonID, LastName,
FirstName, Address, and City:
Example 1
CREATETABLE Persons ( PersonID int,
LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255)
)
a. SQL DROP Command:
• The DROP TABLE statement is used to drop an existing table in a database
• A SQL drop table is used to delete a table definition and all the data from a table.
• It is used to delete both the structure and record stored in the table.
RESULT:
EX. NO: 2 DATABASE DESIGN USING CONCEPTUAL MODELING (ER-EER) –
TOP-DOWN APPROACH MAPPING CONCEPTUAL TO RELATIONAL
DATABASE AND VALIDATE USING NORMALIZATION
AIM:
DESCRIPTION:
ER model
ER model stands for an Entity-Relationship model. It is a high-level data model. This
model is used to define the data elements and relationship for a specified system.
ER MODEL to RELATIONAL MAPPING
The database can be represented using the notations, and these notations can be reduced to a
collection of tables.
In the database, every entity set or relationship set can be represented in tabular form.
RESULT:
EX. NO: 3 IMPLEMENT DATABASE USING SQL DATA DEFINITION
DATE: WITH VIEWS
AIM:
VIEWS DESCRIPTION:
A database view is a logical or virtual table based on a query. Views are queried just like tables.
To create the view, we can select the fields from one or more tables present in database.
A view can either have specific rows based on certain condition or all the rows of a table. A
DBA or view owner can drop a view with the DROP VIEW command.
TYPES OF VIEWS
• Updatable views – Allow data manipulation
• Read only views – Do not allow data manipulation
Sample table: Student_Detail
1 Stephan Delhi
2 Kathrin Noida
3 David Ghaziabad
4 Alina Gurugram
Student_Marks
1 Stephan 97 19
2 Kathrin 86 21
3 David 74 18
4 Alina 90 20
Creating view:
A view can be created using CREATE VIEW statement. Create a view from a single table or
multiple tables.
Syntax:
CREATE VIEW view_name AS SELECT column1, column2..... FROM table_name
WHERE condition;
1. Creating View from a single table
In this example, we create a View named DetailsView from the table Student_Detail.
Query:
CREATE VIEW DetailsView AS SELECT NAME, ADDRESS
FROM Student_Details WHERE STU_ID < 4;
Just like table query, we can query the view to view the data.
SELECT * FROM DetailsView;
2. Creating View from multiple tables
View from multiple tables can be created by including multiple tables in SELECT statement.
In this, view is created named MarksView from two tables Student_Detail and Student_Marks.
Query:
CREATE VIEW MarksView AS
SELECT Student_Detail.NAME, Student_Detail.ADDRESS, Student_Marks.MARKS FROM
Student_Detail, Student_Mark
WHERE Student_Detail.NAME = Student_Marks.NAME;
To display data of View MarksView:SELECT * FROM MarksView;
3. Deleting View - A view can be deleted using the Drop View statement.
Syntax: DROP VIEW view_name;
Example: If we want to delete the View MarksView, we can do this as:
DROP VIEW MarksView;
4. SQL Updating a View -
A view can be updated with the CREATE OR REPLACE VIEW statement.
SQL CREATE OR REPLACE VIEW Syntax
CREATE OR REPLACEVIEW view_name AS SELECTcolumn1, column2, ...
FROM table_name
WHERE condition;
RESULT:
EX. NO: 4 QUERY THE DATABASE USING SQL MANIPULATION
DATE:
AIM:
DESCRIPTION:
SQL DATA MANIPULATION LANGUAGE (DML)
DML commands are SQL commands, used to manipulation of data i.e., modify the data
present in the database
It is responsible for all form of changes in the database.
List of DML commands:
INSERT : It is used to insert data into a table.
UPDATE: It is used to update existing data within a table.
DELETE : It is used to delete records from a database table.
SELECT: It is used to query or retrieve data from a table in the database
a. SQL INSERT: SQL INSERT statement is used to insert a single or multiple data into row
of a table.
Syntax:
INSERT INTO TABLE_NAME
(col1, col2, col3,. ..................... col N)
VALUES (value1, value2, value3, ....................... valueN);
Or INSERT INTO TABLE_NAME
VALUES (value1, value2, value3, ....................... valueN);
For example:
In SQL, You can insert the data in two ways:
Without specifying column name
By specifying column name
Sample Table - EMPLOYEE
To fetch the EMP_ID of all the employees, use the following query: SELECT EMP_ID FROM
EMPLOYEE;
To fetch the EMP_NAME and SALARY, use the following query: SELECT EMP_NAME, SALARY
FROM EMPLOYEE;
To fetch all the fields from the EMPLOYEE table, use the following query: SELECT * FROM
EMPLOYEE
RESULT:
EX. NO: 5a QUERYING/MANAGING THE DATABASE USING SQL
DATE: PROGRAMMING PROCEDURES
AIM:
Table Creation:
create table bank(acc_no number, name varchar2(10), bal number);
Table created.
RESULT:
EX. NO: 5b QUERYING/MANAGING THE DATABASE USING SQL
DATE: PROGRAMMING FUNCTIONS
AIM:
TABE CREATION:
create table bank_acc(acc_no number, b_name varchar2(10), balance number);
Table created.
insert into bank_acc values (100,‘SBI‘, 25000)
1 row created.
insert into bank_acc values (101,‘SBT‘, 5000)
1 row created.
insert into bank_acc values (102,‘FEDERAL‘, 10000)
1 row created.
insert into bank_acc values (103,‘AXIS‘,15000)
1 row created.
insert into bank_acc values (104,‘CANARA‘, 50000)
1 row created
select * from bank_acc;
WITHDRAW FUNCTION:
Create a function for withdrawing money from an account in bank
PROGRAM:
create or replace function withdraw (n in number, amt in number) return number is b number;
begin
select balance into b from bank_acc where acc_no=n;
if b-500>amt then
b:=b-amt;
update bank_acc set balance=b where acc_no=n;
else
dbms_output.put_line('can not withdraw');
end if;
return b;
end;
/ Function created
WITHDRAW FUNCTION CALL:
Calling function from a PL\SQL block:
Declare n number; begin
n:=withdraw(100,20000); end/
Statement processed.
select * from bank_acc;
Calling function from a PL\SQL block: declare
n number;
begin n:=withdraw(101,20000);
end/
can not withdraw Statement processed. select * from bank_acc;
DEPOSIT FUNCTION:
Create a function for depositing money to an account in a bank
create or replace function deposit(n in number, amt in number) return number is b number;
begin
select balance into b from bank_acc where acc_no=n;
b:=b+amt;
update bank_acc set balance=b where acc_no=n;
return b;
end
/ Function created
DEPOSIT FUNCTION CALL
Calling function from a PL/SQL block
declare
n number; begin
n:=deposit(104,5000); end/
Statement processed.
select * from bank_acc;
RESULT:
EX. NO: 5c QUERYING/MANAGING THE DATABASE USING SQL
DATE: PROGRAMMING TRIGGERS
AIM:
SYNTAX:
Create trigger trigger name BEFORE | AFTER
DELETE, INSERT, UPDATE
ON table name FOR EACH ROW BEGIN
Executable-statements END;
Database creation:
create table student(sid number(4), name varchar(30), sub1 number(2), sub2 number(2), sub3
number(2), total number(3), per number(3));
Table Description: Desc student;
RESULT:
EX. NO: 5d CREATION OF A DATABASE USING SQL QUERIES DDL, DML
DATE:
AIM
DELETE
SQL> delete from student where sno=‘03‘; 1 rows deleted
SQL>select * from student;
RESULT:
EX. NO: 6 DATABASE DESIGN USING NORMALIZATION
DATE:
AIM:
DESCRIPTION:
NORAMALIZATION OF TABLE
Database normalization is the process of removing redundant data from tables in order to
improve storage efficiency, data integrity, and scalability
Normalization is process of minimizing redundancy from a relation. Redundancy in relation
may cause insertion, deletion, and update anomalies. So, it helps to minimize redundancy in relations.
Normal forms are used to eliminate or reduce redundancy in database tables
FIRST NORMAL FORM
EMPLOYEE table:
14 John 7272826385, UP
9064738238
The decomposition of the EMPLOYEE table into 1NF has been shown below:
2. SECOND NORMAL FORM:
TEACHER table
25 Chemistry 30
25 Biology 30
47 English 35
83 Math 38
83 Computer 38
THIRD NORMAL FORM (3NF)
EMPLOYEE_DETAIL table:
RESULT:
EX. NO : 6a SQL PROGRAMMING USING FUNCTIONS
DATE:
AIM:
RESULT:
EX. NO: 6b FUNCTIONS IN SQL PROGRAMMING
DATE:
AIM:
FUNCTION CREATION
create or replace function add(n1 in number, n2 in number) return number is
n3 number(8);
begin
n3 :=n1+n2;
return n3;
end;
/
FUNCTION CALL: Program to call the function add()
DECLARE
n3 number(2); BEGIN
n3 := add(11,22);
dbms_output.put_line('Addition is: ' || n3); END;
/
RESULT:
EX. NO: 7 DEVELOP DATABASE APPLICATIONS USING IDE (NETBEANS)
DATE:
AIM:
JDBC DESCRIPTION
Java has defined its own API (JDBC API) that uses JDBC drivers (written in Java language). JDBC
API is used to handle database using Java program and can perform the following activities:
1. Connect to the database
2. Execute queries and update statements to the database
3. Retrieve the result received from the database.
Java Database Connectivity with 5 Steps
There are 5 steps to connect any java application with the database using JDBC.
These steps are as follows:
1) Register the driver class
2) Create the connection object
3) Create the Statement object
4) Execute the query
5) Close the connection object
Java program code Test.java
import java.sql.*; class TestDB
{
public static void main(String ar[])
{
Try
{
String url="jdbc:odbc:mydsn";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection(url);
Statement st=c.createStatement();
ResultSet rs=st.executeQuery("select * from login");
while(rs.next())
{
System.out.println(rs.getString(1) + "" + rs.getString(2)+ "" rs.getString(2));
}
}
catch(Exception ee)
{
System.out.println(ee);
} } }
RESULT:
EX. NO: 8 DATABASE DESIGN USING EER-to-ODB MAPPING/ UML CLASS
DATE: DIAGRAM
AIM:
PROGRAM:
+-------------------+ +------------------+
| Author | | Book |
+-------------------+ +------------------+
| AuthorID | | ISBN |
| FirstName | | Title |
| LastName | | PublicationYear |
| BirthDate | | AuthorID (FK) |
+-------------------+ +------------------+
RESULT:
EX. NO: 9 OBJECT FEATURES OF SQL-UDTS AND SUB-TYPES, TABLES USING
DATE: UDTS, INHERITANCE, METHOD DEFINITION
AIM:
RESULT:
EX. NO: 10 QUERYING THE OBJECT-RELATIONAL DATABASE
DATE: USING OBJET QUERY LANGUAGE
AIM:
RESULT: