Taran Dbms
Taran Dbms
Pratical No.1:-
Introduction to Database Management System(DBMS)and Structured Query
Language(SQL).
Solution-
What is a Database Management System.
A database management system (DBMS) is a software tool that enables users to manage a database
easily. It allows users to access and interact with the underlying data in the database. These actions can
range from simply querying data to defining database schemas that fundamentally affect the database
structure.
Furthermore, DBMS allow users to interact with a database securely and concurrently without interfering
with each user and while maintaining data integrity.
The DBMS manages the data; the database engine allows data to be accessed, locked and modified; and
the database schema defines the database's logical structure. These three foundational elements help
provide concurrency, security, data integrity and uniform data administration procedures. The DBMS
supports many typical database administration tasks, including change management, performance
monitoring and tuning, security, and backup and recovery. Most database management systems are also
responsible for automated rollbacks and restarts as well as logging and auditing of activity in databases
and the applications that access them.
The DBMS provides a centralized view of data that can be accessed by multiple users from multiple
locations in a controlled manner. A DBMS can limit what data end users see and how they view the data,
providing many views of a single database schema. End users and software programs are free from
having to understand where the data is physically located or on what type of storage medium it resides
because the DBMS handles all requests.
The DBMS can offer both logical and physical data independence to protect users and applications from
having to know where data is stored or from being concerned about changes to the physical structure of
data. So long as programs use the application programming interface (API) for the database that the
DBMS provides, developers won't
Database Management System GU-2023-1436
Storage engine. This basic element of a DBMS is used to store data. The DBMS must interface with
a file system at the operating system (OS) level to store data. It can use additional components to
store data or interface with the actual data at the file system level.
Metadata catalog. Sometimes called a system catalog or database dictionary, a metadata catalog
functions as a repository for all the database objects that have been created. When databases and
other objects are created, the DBMS automatically registers information about them in the metadata
catalog. The DBMS uses this catalog to verify user requests for data, and users can query the catalog
for information about the database structures that exist in the DBMS. The metadata catalog can
include information about database objects, schemas, programs, security, performance,
communication and other environmental details about the databases it manages.
Database access language. The DBMS also must provide an API to access the data, typically in the
form of a database access language to access and modify data but may also be used to create database
objects and secure and authorize access to the data. SQL is an example of a database access language
and encompasses several sets of commands, including Data Control Language for authorizing data
access, Data Definition Language for defining database structures and Data Manipulation Language
for reading and modifying data.
Optimization engine. A DBMS may also provide an optimization engine, which is used to parse
database access language requests and turn them into actionable commands for accessing and
modifying data.
Query processor. After a query is optimized, the DBMS must provide a means for running the query
and returning the results.
Lock manager. This crucial component of the DBMS manages concurrent access to the same data.
Locks are required to ensure multiple users aren't trying to modify the same data simultaneously.
Log manager. The DBMS records all changes made to data managed by the DBMS. The record of
changes is known as the log, and the log manager component of the DBMS is used to ensure that log
Database Management System GU-2023-1436
records are made efficiently and accurately. The DBMS uses the log manager during shutdown and
startup to ensure data integrity, and it interfaces with database utilities to create backups and run
recoveries.
Data utilities. A DBMS also provides a set of utilities for managing and controlling database
activities. Examples of database utilities include reorganization, runstats, backup and copy, recover,
integrity check, load data, unload data and repair database.
What is SQL
Database Management System GU-2023-1436
Structured query language (SQL) is a programming language for storing and processing information in a
relational database. A relational database stores information in tabular form, with rows and columns
representing different data attributes and the various relationships between the data values. You can use
SQL statements to store, update, remove, search, and retrieve information from the database. You can
also use SQL to maintain and optimize database performance.
History of SQL
SQL was invented in the 1970s based on the relational data model. It was initially known as the
structured English query language (SEQUEL). The term was later shortened to SQL. Oracle, formerly
known as Relational Software, became the first vendor to offer a commercial SQL relational database
management system.
Pratical No 2.
To write a query with a function of DDL commands such as create,alter,drop
DDL is used as an abbreviation for Data Definition Language. DDL refers to a computer
language that is primarily used for creating as well as modifying the structure of the database
objects present in a database. Such database objects include indexes, tables, schemas, views,
and many more.
DDL is also referred to as a data description language in certain contexts since it describes the
records and fields in the DB (database) tables.
Create
Alter
Drop
Create
The CREATE command builds a new table. It has a predefined syntax, and the CREATE statement
syntax goes like this:
Example
id int,
lname char(20));
Output
Database Management System GU-2023-1436
Alter
The alter command modifies any existing table in a database. The Alter command can add up an
additional column, drop the existing columns and even change the data types of various columns
involved in a DB table. Read more on the ALTER command here.
Syntax
Example
Output
Drop
The DROP command is used in order to delete objects, like a table, view or index. We cannot rollback
the DROP statement. Thus, once a certain object is destroyed, there would be no way at all to recover it.
Example
DROP TABLE TARANVEER
Output
Database Management System GU-2023-1436
Database Management System GU-2023-1436
Practical No.3
Create a table studmarks with following attributes name data type:
Name DataType
Rollno number (6)
Regnumber number (14)
Semester number (1)
CGPA number (2,4)
(a) Add the constraints UNIQUE for regnumber attribute from studmarks table.
(b) Remove the constraints for the regnumber attribute.
(c) Modify the data type of regnumber to varchar (16).
SOLUTION:
Query:
create table stud_marks(rollno numeric(6),regnumber numeric(14),semester numeric(1),cgpa
numeric(2,4));
Output-
Database Management System GU-2023-1436
Describe stud_marks;
Output:
a) Add the constraints UNIQUE for regnumber attribute from stud_marks table
Unique Constraint: SQL Constraints Unique constraints in SQL is used to check whether the sub-
query has duplicate tuples in its result. It returns a boolean value indicating the presence/absence
of duplicate tuples. Unique constraint returns true only if the subquery has no duplicate tuples, else
it returns false.
Query-
alter table stud_marks ADD UNIQUE (regnumber);
Output-
b)alter table stud_marks ADD UNIQUE (regnumber); Remove the constraints for the regnumber
attribute.
Syntax:
Query:
Output-
Output-
Database Management System GU-2023-1426
PRACTICAL No.4
Create a student table and describe the Schema of the student Table:
Name DataType
ROLLNO Number (6)
NAME VARCHAR (15)
DEPT VARCHAR (10)
CITY VARCHAR (1`5)
DOB DATE
GENDER CHAR(1)
a) Add foreign key constraint for the column rollno from studmarks that refers rollno
from student table.
b) Add one more column age in student table with NOT NULL constraint in the
student table.
c) Remove the column city from the student table.
d) RENAME THE TABLE:
i. Change the name of the table student to stud.
ii. Change the name of the attribute dob to dateofbirth.
e) DROP THE TABLE:
i. Drop the table stud.
SOLUTION:
• Query:
Create table student (rollnonumber(6)primary key,name varchar2(15),dept varchar2(10),city
varchar2(15),dob date, gender char(1),foreign key(rollno) references stud_marks(rollno));
• Output:
12
Database Management System GU-2023-1426
a) Add foreign key constraint for the column rollno from studmarks that refers rollno
from student table.
Foreign key Constraint: A foreign key is a key used to link two tables together and
sometimesit is called as referencing key. The relationship between two tables matches
the primary key inone table with foreign key in second table. This constraint uniquely
identifies a row or recordsin another table.
Syntax:
Alter table Student1 add foreign key (Rollno) references Stud_mark (Rollno);
• Output:
b) Add one more column age in student table with NOT NULL constraint in the student
table.
Not Null Constraint: This ensures that a cannot have null value.
• Syntax:
13
Database Management System GU-2023-1426
Alter table table_name add Column_name datatype (data size) Not Null;
• Query:
alter table student add age int not null;
• Output:
Syntax:
• Query:
alter table student drop column city;
• Output:
14
Database Management System GU-2023-1426
Describe student;
• Query:
rename student to stud;
• Output:
15
Database Management System GU-2023-1426
Describe stud;
16
Database Management System GU-2023-1426
Describe student;
• Syntax:
17