SlideShare a Scribd company logo
Section One : SQL Commands
Outline
o These SQL commands are mainly categorized into five categories:
o DDL – Data Definition Language
o DQL – Data Query Language
o DML – Data Manipulation Language
o DCL – Data Control Language
o TCL – Transaction Control Language
PreparedbyBefkadu
Section One : SQL Commands
PreparedbyBefkadu
DDL
Create
Alter
Drop
Truncate
DML
Insert
Update
Delete
DCL
Grant
Revoke
TCL
Commit
Rollback
Save Point
DQL
Select
What is Data ?
o SQL commands are like instructions to a table. It is used to interact with the database
with some operations. It is also used to perform specific tasks, functions, and queries of
data. SQL can perform various tasks like creating a table, adding data to tables,
dropping the table, modifying the table, set permission for users.
o These SQL commands are mainly categorized into five categories:
o DDL – Data Definition Language
o DQL – Data Query Language
o DML – Data Manipulation Language
o DCL – Data Control Language
o TCL – Transaction Control Language
DDL (Data Definition Language)
o DDL or Data Definition Language actually consists of the SQL commands that can be used to define the database
schema. It simply deals with descriptions of the database schema and is used to create and modify the structure of
database objects in the database. DDL is a set of SQL commands used to create, modify, and delete database
structures but not data. These commands are normally not used by a general user, who should be accessing the
database via an application.
o List of DDL commands:
o CREATE: This command is used to create the database or its objects (like table, index, function, views, store procedure,
and triggers).
o DROP: This command is used to delete objects from the database.
o ALTER: This is used to alter the structure of the database.
o TRUNCATE: This is used to remove all records from a table, including all spaces allocated for the records are removed.
o COMMENT: This is used to add comments to the data dictionary.
o RENAME: This is used to rename an object existing in the database.
DQL (Data Query Language)
oDQL statements are used for performing queries on the data within schema
objects. The purpose of the DQL Command is to get some schema relation based
on the query passed to it. We can define DQL as follows it is a component of SQL
statement that allows getting data from the database and imposing order upon it. It
includes the SELECT statement. This command allows getting the data out of the
database to perform operations with it. When a SELECT is fired against a table or
tables the result is compiled into a further temporary table, which is displayed or
perhaps received by the program i.e. a front-end.
oList of DQL:
o SELECT: It is used to retrieve data from the database.
DML(Data Manipulation Language)
o The SQL commands that deal with the manipulation of data present in the database belong to DML or Data
Manipulation Language and this includes most of the SQL statements. It is the component of the SQL statement
that controls access to data and to the database. Basically, DCL statements are grouped with DML statements.
o List of DDL commands:
o CREATE: This command is used to create the database or its objects (like table, index, function, views, store procedure,
and triggers).
• List of DML commands:
o INSERT: It is used to insert data into a table.
o UPDATE: It is used to update existing data within a table.
o DELETE: It is used to delete records from a database table.
o LOCK: Table control concurrency.
o CALL: Call a PL/SQL or JAVA subprogram.
o EXPLAIN PLAN: It describes the access path to data.
DCL (Data Control Language)
oDCL includes commands such as GRANT and REVOKE which mainly deal
with the rights, permissions, and other controls of the database system.
oList of DCL commands:
oGRANT: This command gives users access privileges to the database.
Syntax:
o GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOTHER_USER;
oREVOKE: This command withdraws the user’s access privileges given by using
the GRANT command.
o REVOKE SELECT, UPDATE ON MY_TABLE FROM USER1, USER2;
TCL (Transaction Control Language)
oTransactions group a set of tasks into a single execution unit. Each
transaction begins with a specific task and ends when all the tasks in the
group are successfully completed. If any of the tasks fail, the transaction
fails. Therefore, a transaction has only two results: success or failure. You
can explore more about transactions here. Hence, the following TCL
commands are used to control the execution of a transaction:
o COMMIT: Commits a Transaction.
o ROLLBACK: Rollbacks a transaction in case of any error occurs.
o SAVEPOINT: Sets a save point within a transaction.
DDL
• DDL changes the structure of the table like creating a table, deleting a table,
altering a table, etc.
• All the command of DDL are auto-committed that means it permanently
save all the changes in the database.
• Here are some commands that come under DDL:
• CREATE
• ALTER
• DROP
• TRUNCATE
DDL
• DDL changes the structure of the table like creating a table, deleting a table,
altering a table, etc.
• All the command of DDL are auto-committed that means it permanently
save all the changes in the database.
• Here are some commands that come under DDL:
• CREATE
• ALTER
• DROP
• TRUNCATE
CREATE Command for DATABASE
SQL Server Database can be Created, Alter by
• Graphically using SQL Server Management Studio(SSMS) or
• Using Query
CREATE DATABASE [Database_Name_You_Want_To_Create]
Example :
CREATE DATABASE CRMS;
Alter Command for DATABASE
Rename the Database
• Graphically using SQL Server Management Studio(SSMS) or
• Using Alter Command
ALTER DATABASE [Database_Name_You_Want_To_Rename] Modify Name = [NEW_DB_NAME]
Example :
ALTER DATABASE CRMS Modify Name= ‘CRMS_DEV’;
Example :
sp_renameDB CRMS Modify Name= ‘CRMS_DEV’;
o Using System Stored Procedure
DROP Command for DATABASE
DROP the Database
• Graphically using SQL Server Management Studio(SSMS) or
• Using DROP Command
DROP DATABASE [Database_Name_You_Want_To_DROP]
Example :
DROP DATABASE CRMS;
Example :
-- This command close database connection form other user
-- and delete the database
ALTER DATABASE CRMS set SINGLE_USER With ROLLBACK immediate;
o Delete Database Using ALTER
CREATE Command for TABLE
CREATE TABLE Department (
depid char(5) NOT NULL,
depname char(40),
budget FLOAT,
PRIMARY KEY (depid),
UNIQUE (depname)
)
CREATE TABLE Employee (
empid char(5) NOT NULL,
empname char(40),
depid char(5),
salary float,
PRIMARY KEY (empid),
FOREIGN KEY (depid) REFERENCES Department ON UPDATE CASCADE ON DELETE CASCADE
);
Part One
oDatabase Design/Modeling
oConceptual Design
oLogical Design
oPhysical Design
Objectives
oDesigning a comprehensive Outpatient Management
oSystem (OPMS) database involves conceptual modeling,
ological design, and physical design phases.
oOutpatientMSDB
Conceptual Modeling
oIdentifying Major Entities
oPatients: Information about patients.
oDoctors: Details of doctors providing services.
oAppointments: Scheduled appointments between patients and
odoctors.
oMedicalRecords: Records of medical history, diagnosis, and
oprescriptions.
oBilling: Billing information for appointments.
oMedications: Information about medications prescribed.
Conceptual Modeling: Relationships
o Patients - Appointments: Many-to-Many (A patient can have multiple appointments, and an
o appointment can have multiple patients).
o Doctors - Appointments: One-to-Many (A doctor can have multiple appointments).
o Patients - MedicalRecords: One-to-Many (A patient can have multiple medical records).
o Doctors - MedicalRecords: One-to-Many (A doctor can have multiple medical records).
o Appointments - MedicalRecords: One-to-One (An appointment can have one medical
record).
o Appointments - Billing: One-to-One (An appointment can have one billing record).
o Medications - MedicalRecords: Many-to-Many (A medication can be prescribed in multiple
o medical records, and a medical record can have multiple medications).
Logical Design
oBased on the conceptual model, we create tables with attributes representing
entities and relationships.
o Patients (PatientID, FirstName, LastName, DateOfBirth, Gender, Email, Phone)
o Doctors (DoctorID, FirstName, LastName, Specialization, Email, Phone)
o Appointments (AppointmentID, PatientID, DoctorID, AppointmentDateTime, Notes)
o MedicalRecords (RecordID, PatientID, DoctorID, AppointmentID, DateOfVisit,
o Diagnosis, Prescription)
o Billing (BillID, AppointmentID, Amount, PaymentStatus)
o Medications (MedicationID, MedicationName)
Physical Design
Physical Design
oTranslates logical design into actual database tables, columns, and
relationships.
CREATE TABLE Patients (
PatientID INT PRIMARY KEY IDENTITY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
DateOfBirth DATE,
Gender VARCHAR(10),
Email VARCHAR(100) UNIQUE,
Phone VARCHAR(20),
CONSTRAINT CHK_Gender CHECK (Gender IN ('Male', 'Female‘)
);

More Related Content

Similar to database management system: sql commands lab sql (20)

PPTX
lovely
love0323
 
DOCX
Database Language.docx
antonymwangi31
 
PPTX
Group Members
Farhan Shahani
 
PPTX
DDL And DML
pnp @in
 
PPTX
Lecture - MY-SQL/ SQL Commands - DDL.pptx
umershah0263
 
PPTX
Using Basic Structured Query Language lo1.pptx
TsedaleBayabil
 
PPTX
DDL and DML.pptx ddl vs dml ddl and dml ddl and dml
sadiariasat10
 
PPTX
Unit - II.pptx
MrsSavitaKumbhare
 
PPTX
Introduction to database and sql fir beginers
reshmi30
 
PPT
Sql Commands_Dr.R.Shalini.ppt
DrRShaliniVISTAS
 
PPTX
SQL2.pptx
RareDeath
 
DOCX
Oracle 11g SQL Overview
Prathap Narayanappa
 
PPTX
BASIC_OF_DATABASE_PPT__new[1].pptx
NiyatiMandaliya
 
DOC
Sql server
Puja Gupta
 
PDF
Database Systems - Introduction to SQL (Chapter 3/1)
Vidyasagar Mundroy
 
PPTX
SQL commands in database management system
Darkstorm8
 
PPTX
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Alex Zaballa
 
PPTX
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Alex Zaballa
 
PPTX
Ddl vs dml
shahbazalishahbaz
 
PPTX
Database Management System (DBMS).pptx
GevitaChinnaiah
 
lovely
love0323
 
Database Language.docx
antonymwangi31
 
Group Members
Farhan Shahani
 
DDL And DML
pnp @in
 
Lecture - MY-SQL/ SQL Commands - DDL.pptx
umershah0263
 
Using Basic Structured Query Language lo1.pptx
TsedaleBayabil
 
DDL and DML.pptx ddl vs dml ddl and dml ddl and dml
sadiariasat10
 
Unit - II.pptx
MrsSavitaKumbhare
 
Introduction to database and sql fir beginers
reshmi30
 
Sql Commands_Dr.R.Shalini.ppt
DrRShaliniVISTAS
 
SQL2.pptx
RareDeath
 
Oracle 11g SQL Overview
Prathap Narayanappa
 
BASIC_OF_DATABASE_PPT__new[1].pptx
NiyatiMandaliya
 
Sql server
Puja Gupta
 
Database Systems - Introduction to SQL (Chapter 3/1)
Vidyasagar Mundroy
 
SQL commands in database management system
Darkstorm8
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Alex Zaballa
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Alex Zaballa
 
Ddl vs dml
shahbazalishahbaz
 
Database Management System (DBMS).pptx
GevitaChinnaiah
 

More from trapeziumtrapezoid12 (7)

PDF
Lectures3A.Relational-algebra exercises.pdf
trapeziumtrapezoid12
 
PDF
Intro to SE Lecture Notes 2 (Chapters 1–6).pdf
trapeziumtrapezoid12
 
PPTX
Chap IV Theories of Production and Cost (2).pptx
trapeziumtrapezoid12
 
PPTX
global trends: meaning and nature of international political economy
trapeziumtrapezoid12
 
PPTX
database management system chapter three
trapeziumtrapezoid12
 
PPTX
database management system: SQL operators
trapeziumtrapezoid12
 
PPT
data communication and networking: subnetting
trapeziumtrapezoid12
 
Lectures3A.Relational-algebra exercises.pdf
trapeziumtrapezoid12
 
Intro to SE Lecture Notes 2 (Chapters 1–6).pdf
trapeziumtrapezoid12
 
Chap IV Theories of Production and Cost (2).pptx
trapeziumtrapezoid12
 
global trends: meaning and nature of international political economy
trapeziumtrapezoid12
 
database management system chapter three
trapeziumtrapezoid12
 
database management system: SQL operators
trapeziumtrapezoid12
 
data communication and networking: subnetting
trapeziumtrapezoid12
 
Ad

Recently uploaded (20)

PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Human Resources Information System (HRIS)
Amity University, Patna
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Ad

database management system: sql commands lab sql

  • 1. Section One : SQL Commands Outline o These SQL commands are mainly categorized into five categories: o DDL – Data Definition Language o DQL – Data Query Language o DML – Data Manipulation Language o DCL – Data Control Language o TCL – Transaction Control Language PreparedbyBefkadu
  • 2. Section One : SQL Commands PreparedbyBefkadu DDL Create Alter Drop Truncate DML Insert Update Delete DCL Grant Revoke TCL Commit Rollback Save Point DQL Select
  • 3. What is Data ? o SQL commands are like instructions to a table. It is used to interact with the database with some operations. It is also used to perform specific tasks, functions, and queries of data. SQL can perform various tasks like creating a table, adding data to tables, dropping the table, modifying the table, set permission for users. o These SQL commands are mainly categorized into five categories: o DDL – Data Definition Language o DQL – Data Query Language o DML – Data Manipulation Language o DCL – Data Control Language o TCL – Transaction Control Language
  • 4. DDL (Data Definition Language) o DDL or Data Definition Language actually consists of the SQL commands that can be used to define the database schema. It simply deals with descriptions of the database schema and is used to create and modify the structure of database objects in the database. DDL is a set of SQL commands used to create, modify, and delete database structures but not data. These commands are normally not used by a general user, who should be accessing the database via an application. o List of DDL commands: o CREATE: This command is used to create the database or its objects (like table, index, function, views, store procedure, and triggers). o DROP: This command is used to delete objects from the database. o ALTER: This is used to alter the structure of the database. o TRUNCATE: This is used to remove all records from a table, including all spaces allocated for the records are removed. o COMMENT: This is used to add comments to the data dictionary. o RENAME: This is used to rename an object existing in the database.
  • 5. DQL (Data Query Language) oDQL statements are used for performing queries on the data within schema objects. The purpose of the DQL Command is to get some schema relation based on the query passed to it. We can define DQL as follows it is a component of SQL statement that allows getting data from the database and imposing order upon it. It includes the SELECT statement. This command allows getting the data out of the database to perform operations with it. When a SELECT is fired against a table or tables the result is compiled into a further temporary table, which is displayed or perhaps received by the program i.e. a front-end. oList of DQL: o SELECT: It is used to retrieve data from the database.
  • 6. DML(Data Manipulation Language) o The SQL commands that deal with the manipulation of data present in the database belong to DML or Data Manipulation Language and this includes most of the SQL statements. It is the component of the SQL statement that controls access to data and to the database. Basically, DCL statements are grouped with DML statements. o List of DDL commands: o CREATE: This command is used to create the database or its objects (like table, index, function, views, store procedure, and triggers). • List of DML commands: o INSERT: It is used to insert data into a table. o UPDATE: It is used to update existing data within a table. o DELETE: It is used to delete records from a database table. o LOCK: Table control concurrency. o CALL: Call a PL/SQL or JAVA subprogram. o EXPLAIN PLAN: It describes the access path to data.
  • 7. DCL (Data Control Language) oDCL includes commands such as GRANT and REVOKE which mainly deal with the rights, permissions, and other controls of the database system. oList of DCL commands: oGRANT: This command gives users access privileges to the database. Syntax: o GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOTHER_USER; oREVOKE: This command withdraws the user’s access privileges given by using the GRANT command. o REVOKE SELECT, UPDATE ON MY_TABLE FROM USER1, USER2;
  • 8. TCL (Transaction Control Language) oTransactions group a set of tasks into a single execution unit. Each transaction begins with a specific task and ends when all the tasks in the group are successfully completed. If any of the tasks fail, the transaction fails. Therefore, a transaction has only two results: success or failure. You can explore more about transactions here. Hence, the following TCL commands are used to control the execution of a transaction: o COMMIT: Commits a Transaction. o ROLLBACK: Rollbacks a transaction in case of any error occurs. o SAVEPOINT: Sets a save point within a transaction.
  • 9. DDL • DDL changes the structure of the table like creating a table, deleting a table, altering a table, etc. • All the command of DDL are auto-committed that means it permanently save all the changes in the database. • Here are some commands that come under DDL: • CREATE • ALTER • DROP • TRUNCATE
  • 10. DDL • DDL changes the structure of the table like creating a table, deleting a table, altering a table, etc. • All the command of DDL are auto-committed that means it permanently save all the changes in the database. • Here are some commands that come under DDL: • CREATE • ALTER • DROP • TRUNCATE
  • 11. CREATE Command for DATABASE SQL Server Database can be Created, Alter by • Graphically using SQL Server Management Studio(SSMS) or • Using Query CREATE DATABASE [Database_Name_You_Want_To_Create] Example : CREATE DATABASE CRMS;
  • 12. Alter Command for DATABASE Rename the Database • Graphically using SQL Server Management Studio(SSMS) or • Using Alter Command ALTER DATABASE [Database_Name_You_Want_To_Rename] Modify Name = [NEW_DB_NAME] Example : ALTER DATABASE CRMS Modify Name= ‘CRMS_DEV’; Example : sp_renameDB CRMS Modify Name= ‘CRMS_DEV’; o Using System Stored Procedure
  • 13. DROP Command for DATABASE DROP the Database • Graphically using SQL Server Management Studio(SSMS) or • Using DROP Command DROP DATABASE [Database_Name_You_Want_To_DROP] Example : DROP DATABASE CRMS; Example : -- This command close database connection form other user -- and delete the database ALTER DATABASE CRMS set SINGLE_USER With ROLLBACK immediate; o Delete Database Using ALTER
  • 14. CREATE Command for TABLE CREATE TABLE Department ( depid char(5) NOT NULL, depname char(40), budget FLOAT, PRIMARY KEY (depid), UNIQUE (depname) ) CREATE TABLE Employee ( empid char(5) NOT NULL, empname char(40), depid char(5), salary float, PRIMARY KEY (empid), FOREIGN KEY (depid) REFERENCES Department ON UPDATE CASCADE ON DELETE CASCADE );
  • 15. Part One oDatabase Design/Modeling oConceptual Design oLogical Design oPhysical Design
  • 16. Objectives oDesigning a comprehensive Outpatient Management oSystem (OPMS) database involves conceptual modeling, ological design, and physical design phases. oOutpatientMSDB
  • 17. Conceptual Modeling oIdentifying Major Entities oPatients: Information about patients. oDoctors: Details of doctors providing services. oAppointments: Scheduled appointments between patients and odoctors. oMedicalRecords: Records of medical history, diagnosis, and oprescriptions. oBilling: Billing information for appointments. oMedications: Information about medications prescribed.
  • 18. Conceptual Modeling: Relationships o Patients - Appointments: Many-to-Many (A patient can have multiple appointments, and an o appointment can have multiple patients). o Doctors - Appointments: One-to-Many (A doctor can have multiple appointments). o Patients - MedicalRecords: One-to-Many (A patient can have multiple medical records). o Doctors - MedicalRecords: One-to-Many (A doctor can have multiple medical records). o Appointments - MedicalRecords: One-to-One (An appointment can have one medical record). o Appointments - Billing: One-to-One (An appointment can have one billing record). o Medications - MedicalRecords: Many-to-Many (A medication can be prescribed in multiple o medical records, and a medical record can have multiple medications).
  • 19. Logical Design oBased on the conceptual model, we create tables with attributes representing entities and relationships. o Patients (PatientID, FirstName, LastName, DateOfBirth, Gender, Email, Phone) o Doctors (DoctorID, FirstName, LastName, Specialization, Email, Phone) o Appointments (AppointmentID, PatientID, DoctorID, AppointmentDateTime, Notes) o MedicalRecords (RecordID, PatientID, DoctorID, AppointmentID, DateOfVisit, o Diagnosis, Prescription) o Billing (BillID, AppointmentID, Amount, PaymentStatus) o Medications (MedicationID, MedicationName)
  • 21. Physical Design oTranslates logical design into actual database tables, columns, and relationships. CREATE TABLE Patients ( PatientID INT PRIMARY KEY IDENTITY, FirstName VARCHAR(50), LastName VARCHAR(50), DateOfBirth DATE, Gender VARCHAR(10), Email VARCHAR(100) UNIQUE, Phone VARCHAR(20), CONSTRAINT CHK_Gender CHECK (Gender IN ('Male', 'Female‘) );