Professional Documents
Culture Documents
Piyush DBMS
Piyush DBMS
1426
Practical No.1
Introduction to Database Management System (DBMS) and Structure Query
Language (SQL).
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.
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.
3
Database Management System GU-2023-
1426
3. DML – Data Manipulation Language
4. DCL – Data Control Language
4
Database Management System GU-2023-
1426
Practical No.2
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:
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
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)
SOLUTION:
• 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
• Syntax –
Alter table table_name drop unique (Column_name);
• Query:
alter table stud_marks DROP UNIQUE (regnumber);
• Output:
• 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 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:
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;
• Query:
rename student to stud;
• Output:
15
Database Management System GU-2023-
1426
Describe stud;
16
Describe student;
17