17ETCS002086 Kunal Goswami

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

Name: Kunal Goswami Roll Number: 17ETCS002086

Database Systems Laboratory


B.Tech. 6thSemester

Name : Kunal Goswami


Roll Number : 17ETCS002086
Department : Computer Science and Engineering

Faculty of Engineering & Technology


Ramaiah University of Applied Sciences
Name: Kunal Goswami Roll Number: 17ETCS002086
Ramaiah University of Applied Sciences
Private University Established in Karnataka State by Act No. 15 of 2013

Faculty Engineering & Technology

Programme B. Tech. in Computer Science and Engineering

Year/Semester 3rd Year / 6th Semester


Name of the Laboratory Database Systems Laboratory
Laboratory Code CSC313A
Name: Kunal Goswami Roll Number: 17ETCS002086

Laboratory 1
Title of the Laboratory Exercise: DDL and DML commands
1. Introduction and Purpose of Experiment
Structured Query Language (SQL) is used to pass the query to retrieve and manipulate the
information from database. Depending upon the nature of query, SQL is divided into different
components such as Data Definition Language (DDL) and Data Manipulation Language (DML).
DDL statements create the database, maintain the structure of the database and remove
database objects such as tables, indexes, and users. DML statements are used for managing
data in database such as insert tuples into, delete tuples from, and modify tuples in the
database. By doing this lab, students will be able to execute DDL and DML commands
2. Aim and Objectives
Aim
• To execute Data Definition Language (DDL) and Data Management Language (DML)
commands
Objectives
At the end of this lab, the student will be able to
• Create a database and populate it with data using SQL commands
• Execute DDL and DML commands for the given database

3. Experimental Procedure
i. Analyse the problem statement
ii. Execute DDL and DML commands
iii. Create a database for the given schema
iv. Design SQL commands using DDL and DML commands
v. Test the executed commands
vi. Analyse and discuss the outcomes of your experiment
vii. Document the work

4. Questions
a. Practice DDL and DML commands
b. Consider the following relational schema that keeps track of the students in a college.
Enter at least five tuples for the relation. Assume appropriate domain and data type
for each field.
STUDENT (StudId, StudName, StudAddress)
Name: Kunal Goswami Roll Number: 17ETCS002086

Execute the following queries based on the above schema


i. Display the details of all the students
ii. Display the name and address of the student with id=101
iii. Insert a new student <105, ‘John’, ‘Bangalore’>
iv. Change the address of the student John to ‘Delhi’
v. Delete the details of a student with student id=105
vi. Add a column to the schema Student with appropriate data type

5. Presentation of Results

Fig 1.1: Displaying the details of all students

Fig 1.2: Display the name and address of the student with id=101

Fig 1.3: Inserting a new student <105, ‘John’, ‘Bangalore’>

Fig 1.4: Changing the address of the student John to ‘Delhi’

Fig 1.5: Deleting the details of a student with student id=105


‘Delhi’
Name: Kunal Goswami Roll Number: 17ETCS002086

Fig 1.6: Add a column to the schema Student with appropriate data type

6. Conclusions
‘Delhi’
Form this experiment we can conclude that how does schema do describe a database. And
how we can use DDL and DML to manipulate and store the data into the database.
7. Comments
1. Limitations of Experiments
Limitation of the experiment is that the relation database
2. Limitations of Results
Limitation of the result is the age attribute. Which is completely NULL. Which means
there should not be ‘age’ if all the tuples of age are NULL.
3. Learning happened
We learned the basic SQL commands to make, display and manipulate the database.
4. Recommendations
Relational database can be better to start with.
Name: Kunal Goswami Roll Number: 17ETCS002086

Laboratory 2
Title of the Laboratory Exercise: Requirement analysis and data modelling
1. Introduction and Purpose of Experiment
The requirements analysis phase produce both data requirements and functional
requirements. The data requirements are used as a source of database design and should be
specified as detailed and complete form as possible. In data modelling, the designers first
create a conceptual model of how data items relate to each other. By doing this lab, students
will be able to perform data modelling of the application.

2. Aim and Objectives


Aim
• To analyse the given application and create a data model
Objectives
At the end of this lab, the student will be able to
• Identify functional and data requirements from problem statement
• Create a data model from the data requirements

3. Experimental Procedure
• Read the problem statement and identify requirements
• Perform data modelling
• Document the requirements and ER diagram

4. Question
Students have to choose one of the following problem statements and develop the software
solution. The Course leader is the customer. Contact the Course leader for any clarifications.
1. Library management system
2. Hospital management system
3. Employee management system
Perform the following based on the problem statement you have chosen
a. Analyse the given application and list the functional and data requirements
b. Perform data modelling based on the identified data requirements

5. Calculations
a. Analysis the given application and lust the functional and data requirements
Name: Kunal Goswami Roll Number: 17ETCS002086

Item Detail
Requirement Tag FR1
Requirement statement The system should allow each employee to authenticate using login ID
and password.
Dependent on requirements none
User/system interacting with Staff
the requirement
Item Detail
Requirement Tag FR4
Requirement statement The system should display the assigned project with deadline, team and
with each department.
Dependent on requirements FR1, FR2, FR3, FR4
User/system interacting Staff
with the requirement
Item Detail
Requirement Tag FR2
Requirement statement The system should record the details of all the employees in a
department.
Dependent on requirements FR1
User/system interacting with Staff
the requirement

Item Detail
Requirement Tag FR3
Requirement statement The system should have teams of employees with the team details
Dependent on requirements FR1, FR2

User/system interacting with Staff


the requirement

Item Detail
Requirement Tag FR4
Requirement statement The system should a allot each employee a department and each
department should have a head of department
Dependent on requirements FR1
User/system interacting with Staff
the requirement
Name: Kunal Goswami Roll Number: 17ETCS002086

6. Presentation of Results
Name: Kunal Goswami Roll Number: 17ETCS002086

7. Conclusions
From this experiment we can conclude how we can elaborate the functional requirement
using Entity relationship diagram.
8. Comments
1. Limitations of Results
There is limited feature in our system.
2. Learning happened
Learned to write functional requirements and to form ER diagram
4. Recommendation
More feature can be added to the system
Name: Kunal Goswami Roll Number: 17ETCS002086

Laboratory 3
Title of the Laboratory Exercise: implement constraints and built in functions
1. Introduction and Purpose of Experiment
Constraints are the rules which are enforced on the data being stored in a table. There are
constraints that can be applied to a table such as NOT NULL, UNIQUE, PRIMARY KEY and
FOREIGN KEY. SQL has many built-in functions for performing calculations on data. In SQL, a
built-in function is a piece for programming that takes zero or more inputs and returns a value.
By doing this lab, students will be able to implement constraints and built in functions on the
database.

2. Aim and Objectives


Aim
• To design and implement constraints on the data using SQL commands
• To implement built in functions in SQL
Objectives
At the end of this lab, the student will be able to
• Identify different types of constraints on the data
• Apply constraints on the data in different ways
• Implement built-in functions in SQL

3. Experimental Procedure
i. Analyse the problem statement
ii. Design SQL commands using appropriate constraints
iii. Execute the SQL commands
iv. Test the executed commands
v. Document the Results
vi. Analyse and discuss the outcomes of your experiment

4. Questions
Consider the relational schema given below.
PLAYER_DETAILS (PCode, PName, DOB, City, Score)
MATCH_DETAILS (MatchID, MatchName, PCode)
a. Apply the following constraints on the given database schema. Enter appropriate
tuples to show the purpose of each constraint.
Name: Kunal Goswami Roll Number: 17ETCS002086

i. Not NULL
ii. Default
iii. Unique
iv. Primary key
v. Foreign key
b. Execute the following built-in functions in SQL using Netbeans IDE
i. String functions
ii. Date functions
iii. Numeric functions

5. Presentation of Results

Fig 4.1: Creating and describing table PLAYER_DETAILS and MATCH_DETAILS


Name: Kunal Goswami Roll Number: 17ETCS002086

Fig 4.2: describing constraints of table PLAYER_DETAILS and MATCH_DETAILS


Name: Kunal Goswami Roll Number: 17ETCS002086

Fig 4.3: inserting data by showing the constraints “not NULL”, “default” and “primary key in table
PLAER_DETAILS

Fig 4.4: inserting data by showing the purpose of foreign key


Name: Kunal Goswami Roll Number: 17ETCS002086

Executing string, numeric and date functions in SQL using Netbeans IDE

Fig 4.5: query in NetBeans

Fig 4.6: Result of above query

6. Analysis and Discussions


a. The purpose of default constraints is to put the given default value which is given
during the time of table schema, when the value on the particular attribute is not
mentioned or it is mentioned as default.
b. Not NULL constraint is to not to allow the user to leave the particular attribute empty
or value as NULL.
c. Unique constraint is use to maintain the uniqueness of entire tuples for an attribute
in which the constraint is applied, example – primary key is by default a unique key.
Name: Kunal Goswami Roll Number: 17ETCS002086

d. Primary key constraint is is used to uniquely identify a tuple from the others. So, we
can’t have duplicate entries with the same primary key
e. Foreign key is used to connect a table attribute to another table’s. This makes it so
that the table with foreign key to another table can reference this other table for that
particular attribute. This constraint is present to make sure that the tuple in table with
foreign key referencing a tuple from the other table isn’t deleted.

7. Conclusions
Form this experiment we can conclude that how we can restrict the data entry into the table
by using constraints like unique, primary key, default etc. and how we can use NetBeans IDE
to implement SQL functions.

8. Comments
1. Limitations of Experiments
Lot of experimentation required to understand table structure.
2. Limitations of Results
Difficult to manipulate data when so many constraints present
3. Learning happened
We learnt how to connect to database in NetBeans and how to execute queries there.
We also learnt how to use default, unique key, foreign key and primary key constraints
in MySQL.
4. Recommendations
Use an IDE to perform all the queries to make it easier
Name: Kunal Goswami Roll Number: 17ETCS002086

Laboratory 4
Title of the Laboratory Exercise: Java database programming
1. Introduction and Purpose of Experiment
The SQL includes commands to define view on the data. A view contains rows and columns,
just like a real table. Java uses JDBC (Java Database Connectivity) to connect to databases.
JDBC allows to connect to a wide-range of databases such as Oracle, MySQL, etc. By doing this
lab, students will be able to implement views in SQL and connect the developed database with
the application.

2. Aim and Objectives


Aim
• To design and implement views on the data using SQL commands
• To connect to the relational database in Java
Objectives
At the end of this lab, the student will be able to
• Design and execute views using SQL commands
• Perform database programming in Java

3. Experimental Procedure
i. Analyse the problem statement
ii. Execute the built-in functions in SQL
iii. Design and execute the view statements in SQL
iv. Test the executed commands
v. Document the Results
vi. Analyse and discuss the outcomes of your experiment
4. Questions
a. Create a table MANGER with attributes such as Name, Id, Department, Address, and
Salary. Write SQL statements for the following expressions.
i. Create a view ‘MANAGER_VIEW’ to display the details such as name and
department of each manager
ii. Display the name of the manager from MANAGER_VIEW whose department
is ‘Information Technology’
iii. Drop the views generated
Name: Kunal Goswami Roll Number: 17ETCS002086

b. Write a Java program to do the following operations


i. Insert the details of the Managers into the table
ii. Display all the details of the Managers in the ascending order of their names
iii. Count the number of Managers staying in each location and display the
address and the total number
iv. Display the number of Managers in each location. Only include locations
with more than 3 Managers

5. Presentation of Results
Name: Kunal Goswami Roll Number: 17ETCS002086
Name: Kunal Goswami Roll Number: 17ETCS002086

Fig 5.1: java program insert, count and display the database manager

ooutputs:
Name: Kunal Goswami Roll Number: 17ETCS002086

Fig 5.2: output of above java program

6. Analysis and Discussions


SQL statements were executed in MySQL terminal successfully as asked in question’s part one.
These SQL statements were with regarding managing views in MySQL.
Now comes the part two of the question. For this we had to make a Java program and establish
a connection with MySQL Server and execute queries mentioned.
The main code is put in try block to catch an exception in case of a problem. In this try block,
we connect to MySQL Server, use statement.executeQuery() to execute queries, store the
result in a ResultSet and print this set one by one.
Exceptions are caught by the catch block and the exception is shown as a message.
7. Conclusions
We successfully executed the Java program and executed the queries asked in both the part.
Name: Kunal Goswami Roll Number: 17ETCS002086

8. Comments
1. Limitations of Experiments
Limitations of Experiments: If exception not caught, the whole execution stops.

2. Limitations of Results
Limitations of Results: Need to have specific catch blocks or else it becomes difficult to
3. Learning happened
We learnt how to make a connection between Java program and MySQL Server.
4. Recommendations
Use an IDE to its fullest by learning the shortcuts and be clear with basics of MySQL.
Name: Kunal Goswami Roll Number: 17ETCS002086

Laboratory 5
Title of the Laboratory Exercise: Nested queries and Join queries
1. Introduction and Purpose of Experiment
Nesting of queries within another one is known as a nested queries. The query within another
is known as a subquery. The statement containing a subquery is called a Parent Statement.
The parent statement uses the rows returned by the subquery. SQL Join is used for combining
column from two or more tables by using values common to both tables. Join Keyword is used
in SQL queries. By doing this lab, students will be able to implement nested queries and join
queries.

2. Aim and Objectives


Aim
• To design and implement nested queries and join queries using SQL commands
Objectives
At the end of this lab, the student will be able to
• Design nested queries and join queries for the given problem statement
• Execute the nested queries and join queries

3. Experimental Procedure
• Analyse the problem statement
• Create tables with appropriate attributes
• Insert attribute values into the table
• Design nested queries and join queries
• Execute the SQL commands
• Test the executed commands
• Document the Results
• Analyse and discuss the outcomes of your experiment

4. Questions
a. Create a tables for the given relational schema. Assume appropriate data type, and
key constraints for each field.
Player (Name, Id, TeamNo, Score)
Team (TeamNo, TeamName)
b. Write the appropriate query for the following statements using SQL commands
Name: Kunal Goswami Roll Number: 17ETCS002086

i. Find the names of all the players who are in the same Team of ‘Smith’ (use
nested query)
ii. Display the information about players who got Scores more than any player
in TeamNo=1 (use nested query)
iii. Display the players and Team details , in which the TeamNo is same in both
the players and Team (without join)
iv. Display the players and Team details , in which the TeamNo is same in both
the players and Team (use join)
v. Display the players and Team details , in which the TeamNo is same in both
the players and Team (use natural join)
vi. Display the players and their team names, in which the TeamNo is same in
both the players and Team (use left outer join)
vii. Display the team names and the players involved, in which the TeamNo is
same in both the players and Team (use right outer join)
c. Create suitable front end for querying and displaying the results

5. Calculations/Computations/Algorithms
Algorithm:
a. Create a database and create two tables “Player” and “Team” according to the given
schema.
b. Insert some test elements/data in both the tables.
c. Perform the queries based on the above given question.
d. Create a new project in java and design a swing UI using based on any one query
performed above.
e. Write program for the backend of the UI by performing any one query above.

6. Presentation of Results
Name: Kunal Goswami Roll Number: 17ETCS002086

Fig 7.1: creating table “Player” and “Team” and inserting data into the
tables

Fig 7.2: performing queries for the above 7 questions

Outputs:

rst query Fig 7.4: output of second query

Fig 7.5: output of third query


Name: Kunal Goswami Roll Number: 17ETCS002086

Fig 7.6: output of fifth query

Fig 7.7: output of sixth query

Fig 7.8: output of seventh query

User Interface:

Fig 7.9: User interface for the first query


Name: Kunal Goswami Roll Number: 17ETCS002086

7. Conclusions
• From this experiment we can conclude design and implement nested queries and join
queries using SQL commands

8. Comments
1. Limitations of Experiments

2. Limitations of Results

3. Learning happened

4. Recommendations
Name: Kunal Goswami Roll Number: 17ETCS002086

You might also like