DBMD Record Ashok
DBMD Record Ashok
DBMD Record Ashok
Lab Record
M. Ashok Chakravarthi
BU21CSEN0500144
Aim:
To develop an entity relationship diagram for
hospital management system.
Entities:
1)Patient
2)Medical records
3)Hospital
4)Doctor
Attributes:
PName
Pat_id
PDiagnosis
Paddress
Hosp_id
Hosp_Name
HAddress
HCity
Record_id
Date of examination
Problem
Salary
Qualification
DName
Doc_id
Relation:
1. Has a(one to many)
2. Admitted in (many to one)
M. ASHOK
BU21CSEN0500144
DDL COMMANDS
Ashok
BU21CSEN0500144
Create Command:
It is used to create a new table in the database. The user has to give
information like table name, column names, and their datatypes.
Syntax:
Create table student(id number(10) primary key,name char(20),sec char(15));
Alter Command:
This command is used to remove an existing table along with its
structure from the Database.
Syntax:
DROP TABLE table_name;
Truncate Command:
This command is used to remove all rows from the table, but the
structure of the table still exists.
Syntax:
TRUNCATE TABLE table_name;
Drop Table:
This command is used to add, delete or change columns in the existingtable. The
user needs to know the existing table name and can do add, deleteor modify
tasks
easily.
Syntax:
To add a new column to the existing table
ALTER TABLE table_name ADD column_name
DML COMMANDS
Ashok Chakaravarthi
BU21CSEN0500144
DML Commands
The DML commands in Structured Query Language change the data
present in the SQL database. We can easily access, store, modify, update
and delete the existing records from the database using DML commands.
1. SELECT Command
2. INSERT Command
3. UPDATE Command
4. DELETE Command
Insert Command:
Syntax:
Syntax:
Delete Command:
Syntax:
Syntax:
1. Not null:
This constraint tells that we cannot store a null value in a
column. That is, if a column is specified as NOT NULL then we will not be
able to store null in this particular column any more.
2. Unique:
This constraint when specified with a column, tells that all the
values in the column must be unique. That is, the values in any row of a
column must not be repeated.
3. Default:
This constraint specifies a default value for the column when no
value is specified by the user.
4. Check:
This constraint helps to validate the values of a column to
meet a particular condition. That is, it helps to ensure that the value stored
in a column meets a specific condition.
5. Primary key:
A primary key is a field which can uniquely identify each row
in a table. And this constraint is used to specify a field in a table as primary
key.
6. FOREIGN KEY:
A Foreign key is a field which can uniquely identify each
row in a another table. And this constraint is used to specify a field as
Foreign key.
Experiment:8
Use of different of operators for nested sub-queries
Ashok
BU21CSEN0500144
DESCRIPTION:
1 . COUNT
2.SUM
3.AVG
4.MAX
5.MIN
First create a table for employees and insert values in the created table
COUNT:
AVERAGE:
MAX:
MIN:
EXPERIMENT: 9
Implementation of Nested Sub-Queries
ASHOK
BU21CSEN0500144
AIM: implementing of nested sub queries.
A subquery is a query within another query. The outer query is called as main
query and inner query is called as subquery.
A correlated subquery is evaluated once for each row processed by the parent
statement. The parent statement can be a SELECT, UPDATE, or DELETE
statement. Correlated subqueries are used for row-by-row processing. Each
subquery is executed once for every row of the outer query.
ALL:
ANY:
EXPERIMENT:10
USE OF JOINS
M. Ashok
BU21CSEN0500144
OUTER JOINS:
MAKING NULL INTO ZERO’S
VIEW IS CREATED
IN SUBQUERY:
GOING TO JOIN THE TABLE:
IN SQL :
INNER JOIN OPERATION:
LEFT JOIN:
Right join:
EXPERIMENT-11
Ashok.M
BU21CSEN0500144
AIM: To familiarise with Group by and Having Functions.
The GROUP BY Statement in SQL is used to arrange identical data into
groups with the help of some functions. if a particular column has the
same values in different rows, it will arrange these rows in a group.
Employee DB:
Department DB:
Group by with single column:
Table creation:
Displaying a view:
Deleting a Row from a View:
Updating a view:
ASHOK
BU21CSEN0500144
• The trigger can be executed when you run one of the following MySQL
statements on the table: INSERT, UPDATE and DELETE and it can be
invoked before or after the event.
Types of triggers:
Triggers are of two types –
Statement-Level Trigger: It is a trigger, which is fired once for each event that
occurs on a table regardless of how many rows are inserted, updated, or deleted.
Before Update Trigger: It is activated before the update of data in the table.
Before Delete Trigger: It is activated before the data is removed from the table.