DBMS Experiments
DBMS Experiments
1.) Database Management System (DBMS)- It is a program or group of programs that work in
conjunction with the operating system to create, process, store, retrieve, control and manage the
data. It acts as an interface between the application program and the data stored in the Database.
A DBMS has three main components. These are Data Definition Language (DDL), Data Manipulation
Language and Query Facilities (DML/SQL) and software for controlled access of Database as shown
in Figure 1 and are defined as follows:
It allows the users to define the Database, specify the data types, data structures and the constraints
on the data to be stored in the Database.
DML allows users to insert, update, delete and retrieve data from the Database. SQL provides
general query facility.
The relational model represents how data is stored in Relational Databases. A relational database
consists of a collection of tables, each of which is assigned a unique name. Consider a relation
STUDENT with attributes ROLL_NO, NAME, ADDRESS, PHONE, and AGE shown in the table:
STUDENT
i. Attribute- Attributes are the properties that define an entity. e.g. ROLL_NO, NAME,
ADDRESS, PHONE, AGE.
ii. Tuple- Each row in the relation is known as a tuple. The above relation contains 3 tuples,
one of which is shown as:
iii. Relation Schema- A relation schema defines the structure of the relation and represents
the name of the relation with its attributes. e.g.; STUDENT (ROLL_NO, NAME, ADDRESS,
PHONE, and AGE) is the relation schema for STUDENT. If a schema has more than 1
relation, it is called Relational Schema.
iv. Degree- The number of attributes in the relation is known as the degree of the relation.
The STUDENT relation defined above has degree 5.
v. Cardinality-The number of tuples in a relation is known as cardinality.
The STUDENT relation defined above has cardinality 3.
• A DBMS has appropriate languages and interfaces to express database queries and updates.
• Database languages can be used to read, store and update the data in the Database.
1.) Data Definition Language (DDL)
• DDL stands for Data Definition Language. It is used to define database structure or pattern.
• It is used to create schema, tables, indexes, constraints, etc. in the Database.
• Using the DDL statements, you can create the skeleton of the Database.
• Data definition language is used to store the information of metadata like the number of
tables and schemas, their names, indexes, columns in each table, constraints, etc.
These commands are used to define and update the database schema that's why they come under
Data definition language.
DML stands for Data Manipulation Language. It is used for accessing and manipulating data in a
database. It handles user requests.
DCL stands for Data Control Language. It is used to retrieve the stored or saved data.
TCL is used to run the changes made by the DML statement. TCL can be grouped into a logical
transaction.
1. CREATE
2. ALTER
3. DROP
4. TRUNCATE
5. RENAME
THEORY:
Structured Query Language (SQL): SQL, or Structured Query Language, is a domain-specific language
designed for managing and querying relational databases. It provides a standardized way to interact
with databases, making it an essential tool for anyone working with data. SQL commands perform
various database operations, such as creating tables, inserting data, querying information, and
controlling access and security. SQL commands can be categorized into different types, each serving
a specific purpose in the database management process.
Data Definition Language (DDL): DDL, which stands for Data Definition Language, is a subset of SQL
(Structured Query Language) commands used to define and modify the database structure. These
commands create, alter, and delete database objects like tables, indexes, and schemas. The primary
DDL commands in SQL include:
1.) CREATE: This command is used to create a new database object. For example, creating a
new table, a view, or a database.
Syntax:
Example:
The ALTER TABLE statement also adds and drops various constraints on an existing table.
i) To add a new column using Alter table command to the existing table.
Syntax:
ii) To drop a column using Alter Table command from the existing table.
Syntax:
4.) TRUNCATE: The TRUNCATE TABLE command deletes the data inside a table but not the table
itself.
Syntax:
5.) DROP: The DROP TABLE command deletes a table in the Database.
Syntax:
CONCLUSION: Different Data Definition Language(DDL) commands have been successfully studied.
EXPERIMENT-3
• PRIMARY KEY
• FOREIGN KEY
• NOT NULL
• DEFAULT
• UNIQUE
• CHECK
THEORY:
SQL Constraints:
SQL constraints are used to specify rules for the data in a table.
Constraints are used to limit the type of data that can go into a table. This ensures the accuracy and
reliability of the data in the table. The action is aborted if there is any violation between the
constraint and the data action.
Constraints can be column level or table level. Column-level constraints apply to a column, and
table-level constraints apply to the whole table.
PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a table
FOREIGN KEY - Prevents actions that would destroy links between tables
IMPLEMENTATION:
UNIQUE (Name));
Syntax:
EmployeeID INT,
Department VARCHAR(25),
2.) VIOLATING CHECK CONSTRAINT-Inserting a value less than 18 into Age in Employee:
3.) VIOLATING NOT NULL CONSTRAINT-Inserting a null value into ProjectName in Project:
• INSERT
• SELECT
• UPDATE
• DELETE
THEORY:
DML stands for Data Manipulation Language. It is a subset of SQL (Structured Query Language)
that allows users to manipulate data stored in a database. DML commands are primarily used to
retrieve, insert, update, and delete data in database tables.
1.) SELECT:
2.) INSERT:
Syntax: INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
3.) UPDATE:
Syntax: UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
4.) DELETE:
IMPLEMENTATION:
ProductName VARCHAR(100),
Category VARCHAR(100),
StockQuantity INT);
1.) INSERT OPERATION:
i.) Delete from Products where stock quantity is less than 15.