You are on page 1of 17

Database Management System GU-2023-

1426

Practical No.1
Introduction to Database Management System (DBMS) and Structure Query
Language (SQL).

• What is a database management system.


A database management system (DBMS) is system software for creating and managing
databases. A DBMS makes it possible for end users to create, protect, read, update and
delete data in a database. The most prevalent type of data management platform, the DBMS
essentially serves as an interface between databases and users or application programs,
ensuring that data is consistently organized and remains easily accessible.

• What does a DBMS do.


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.

• Components database management system (DBMS)


1. Hardware
Hardware refers to the physical, electronic devices such as computers and hard disks
that offer the interface between computers and real-world systems.

2. Software
Software is a set of programs used to manage and control the database and includes
the database software, operating system, network software used to share the data
with other users, and the applications used to access the data.

3. Data

1
Database Management System GU-2023-
1426
Data are raw facts and information that need to be organized and processed to make
it more meaningful. Database dictionaries are used to centralize, document, control,
and coordinate the use of data within an organization. A database is a repository of
information about a database (also called metadata).

4. Procedures
Procedures refer to the instructions used in a database management system and
encompass everything from instructions to setup and install, login and logout,
manage the day-to-day operations, take backups of data, and generate reports.

5. Database Access Language


Database Access Language is a language used to write commands to access, update,
and delete data stored in a database. Users can write commands using Database
Access Language before submitting them to the database for execution. Through
utilizing the language, users can create new databases, tables, insert data, and delete
data.

• What is Structure Query Language SQL.


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

2
Database Management System GU-2023-
1426
retrieve information from the database. You can also use SQL to maintain and optimize
database performance.
• Why is SQL important.
Structured query language (SQL) is a popular query language that is frequently used in all types
of applications. Data analysts and developers learn and use SQL because it integrates well with
different programming languages. For example, they can embed SQL queries with the Java
programming language to build high-performing data processing applications with major SQL
database systems such as Oracle or MS SQL Server. SQL is also fairly easy to learn as it uses
common English keywords in its statements
• 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.

• These SQL commands are mainly categorized into five categories:


1. DDL – Data Definition Language

2. DQL – Data Query Language

3
Database Management System GU-2023-
1426
3. DML – Data Manipulation Language
4. DCL – Data Control Language

5. TCL – Transaction Control Language

4
Database Management System GU-2023-
1426

Practical No.2

• TO write a Query with a function of DDL commands such as create, alter,


drop.
DDL stands for Data Definition Language.
These commands are used to change the structure of a database and database objects. For
example, DDL commands can be used to add, remove, or modify tables with in a database.

The DDL commands are:

1. CREATE
2. ALTER
3. DROP

• CREATE:
This command is used to create table in the relational database.
This can be done by specifying the names and datatypes of various columns
.
• Syntax:

CREATE TABLE TABLE_NAME


(
column_name1 datatype1,
column_name2 datatype2,
column_name3 datatype3,
column_name4 datatype4
);

CREATE TABLE Piyush


( id
int,
fname char(14));

5
Database Management System GU-2023-
1426
Output :

• ALTER:
Alter command is used for altering the table in many forms like:
1. Add a column
2. Rename existing column
3. Drop a column
4. Modify the size of the column or change datatype of the column

• Syntax

ALTER TABLE table_name ADD( column_name datatype);

Example :
ALTER TABLE Piyush ADD( Address varchar(43));

Output :

6
Database Management System GU-2023-
1426

• DROP :
This command completely removes the table from the database along with the
destruction of the table structure.

• Syntax –
DROP TABLE table_name

Example :
DROP TABLE Piyush

7
Database Management System GU-2023-
1426

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)

Alter the Table:


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:

Creating Stud_marks table:

• Query:
create table stud_marks(rollno numeric(6),regnumber numeric(14),semester numeric(1),cgpa
numeric(2,4));

• Output:

8
Database Management System GU-2023-
1426
describe stud_marks;

• Output:

a) Add the constraints UNIQUE for regnumber attribute from studmarks 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:

describe stud_marks;

9
Database Management System GU-2023-
1426

b) Remove the constraints for the regnumber attribute.

• Syntax –
Alter table table_name drop unique (Column_name);

• Query:
alter table stud_marks DROP UNIQUE (regnumber);

• Output:

• c) Modify the data type of regnumber to varchar (16).

• Syntax –
Alter table table_name modify Column_name datatype(datasize);

• Query:
alter table stud_marks MODIFY regnumber varchar(16);

• Output:

10
Database Management System GU-2023-
1426

describe stud_marks;

11
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:
Creating table student:
• 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 table_name add foreign key (Column_name) references table_name1


(column_name);
Query:

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:
Alter table table_name add Column_name datatype (data size) Not Null;

• Query:
alter table student add age int not null;
13
Database Management System GU-2023-
1426

• Output:

c) Remove the column city from the student table.\

Syntax:
Alter table table_name drop Column Column_name;

• Query:
alter table student drop column city;

• Output:

14
Database Management System GU-2023-
1426

Describe student;

d) RENAME THE TABLE:


i. Change the name of the table student to stud.
• Syntax:
Rename table_name to new_table_name;

• Query:
rename student to stud;

• Output:

15
Database Management System GU-2023-
1426

Describe stud;

ii. Change the name of the attribute dob to dateofbirth.


• Syntax:
Alter table table_name rename column Column_name to new_columnc_name;
• Query:

alter table student rename column dob to dateofbirth;


• Output:

16
Describe student;

e) DROP THE TABLE:


Drop the table stud.
• Syntax:
Drop table table_name;
• Query:
drop table stud;
• Output:

17

You might also like