HIT/ CSE/LOM/ ___
Since 2001
Bhartiya Gramin Punarrachna Sanstha’s
Hi-Tech Institute of Technology, Aurangabad
A Pioneer to Shape Global Technologies
Approved By AICTE, DTE Govt. of Maharashtra & Affiliated to Dr. Babasaheb Ambedkar Technological University, Lonere, Raigad
P-119, Bajajnagar, MIDC Waluj, Aurangabad, Maharashtra, India - 431136P: (0240) 2552240, 2553495, 2553496
DEPARTMENT: COMPUTER SCIENCE & ENGINEERING DEPARTMENT
PRACTICAL EXPERIMENT INSTRUCTION SHEET
EXPERIMENT TITLE: Implement the schemas for Applications.
EXPERIMENT NO.: 01 SUBJECT: DBS
CLASS:TY BTECH SEMESTER: V
Aim: Implement the schemas for Applications.
Implementation of DDL AND DML Commands.
Hardware Requirement: Intel core I5,
1 GB RAM, 256 GB HDD, 15” LCD Monitor, Keyboard, Mouse.
Software Requirement:
ORACLE 10g Or 11g.
Theory:
A database schema is an abstract design that represents
the storage of your data in a database. It describes both the
organization of data and the relationships between tables in a
given database. Developers plan a database schema in advance
so they know what components are necessary and how they will
connect to each other.
Administrator control
Since database schemas provide a clear logical outline
for how data is stored, administrators can validate data in a
secure and organized manner. As a result, administrators are
able to ensure the database is functional and performant.
Additionally, this level of manual control
streamlines database management and compliance with design
constraints and ACID properties.
DDL(Data Definition Language): To make/perform changes to
the physical structure of any table residing inside a
database, DDL is used. These commands when executed are auto-
commit in nature and all the changes in the table are
reflected and saved immediately.
Data Definition Language
In SQL DDL commands are used to create and modify the
structure of a database and database objects. These commands
are CREATE, DROP, ALTER, TRUNCATE, and RENAME. Let us discuss
these commands one at a time.
CREATE
The syntax for create command is:
For creating a database:
CREATE DATABASE database_name;
Creates a database named 'database_name'. Let us create our own database and table
which we will use as a reference throughout this article:
CREATE DATABASE testdb;
For creating a table:
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
.....
columnN datatype
);
CREATE TABLE my_table(
first_name varchar(20),
age INT
);
To drop a table:
DROP TABLE table_name;
deletes the table named 'table_name' if present. ALTER TABLE table_name
ADD column_name column_definition;
TRUNCATE
This command is similar to the drop table command. The only difference is that while
the drop command removes the table as well as its contents, the truncate command only
erases the contents of the table's contents and not the table itself. Let us take an example to be
clearer:
truncate table my_table;
select * from my_table;
RENAME
This command is used to change the name of an existing table. The syntax is
RENAME TABLE table_name TO table_name_new;
DML (Data Manipulation Language)
The SQL commands that deal with the manipulation of data present in the database
belong to DML or Data Manipulation Language and this includes most of the SQL
statements. It is the component of the SQL statement that controls access to data and to the
database. Basically, DCL statements are grouped with DML statements.
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.
LOCK: Table control concurrency.
CALL: Call a PL/SQL or JAVA subprogram.
EXPLAIN PLAN: It describes the access path to data.
Sample Program Code:
CREATE TABLE Persons (
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
DROP TABLE Shippers;
ALTER TABLE Customers
ADD Email varchar(255);
CREATE DATABASE testDB;
DML command sample code:
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode,
Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');
INSERT INTO Customers (CustomerName, City, Country)
VALUES ('Cardinal', 'Stavanger', 'Norway');
DELETE Syntax
DELETE FROM table_name WHERE condition;
DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste';
Delete All Records
DELETE FROM Customers;
UPDATE Syntax
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Extra Programs For Practice:
Perform the following:
1. Rename the table dept as department
2. Add a new column PINCODE with not null constraints to the
existing table DEPT
3. All constraints and views that reference the column are
dropped automatically, along with the column.
4. Rename the column DNAME to DEPT_NAME in dept table
5. Change the data type of column loc as CHAR with size 10
6. Delete table
Conclusion:
Hence we have learn and executed DDL And DML Commands.