In this video, we break down essential SQL DML (Data Manipulation Language) and DDL (Data Definition Language) commands to help you manage and manipulate your database effectively. We cover:
**Insert**: Adding new records to a table.
**Update**: Modifying existing records.
**Delete**: Removing specific records.
**Truncate**: Quickly clearing all records from a table.
**Drop**: Completely removing a table from the database.
🔍 *In This Video:*
1. Creating and inserting data into the `hospitals` table.
2. Using `UPDATE` to modify records.
3. Differentiating between `DELETE` and `TRUNCATE` commands.
4. Dropping the table when it's no longer needed.
**Key Differences**:
`DELETE` vs. `TRUNCATE`: When to use which and why. `DELETE` can remove specific records or all records, while `TRUNCATE` is a fast way to remove all data.
drop table if exists hospitals;
create table hospitals
(
hospital_code int ,
hospital_name varchar(50) ,
location varchar(200),
contact_no bigint,
constraint pk_hospitals primary key (hospital_code,hospital_name)
);
--insert
insert into hospitals values (1, 'Fortis Hospital', 'Bangalore', 9900099000);
insert into hospitals values (2, 'Manipal Hospital', 'Manipal', 9900099222);
insert into hospitals values (3, 'Apollo Hospital', 'Mumbai', 9900099333);
insert into hospitals values (4, 'St. Francis Hospital', 'New York', 17194440001);
insert into hospitals values (4, 'Duke Hospital', 'New York', 17194440022);
select * from hospitals;
-- UPDATE
update hospitals
set hospital_code=50
where hospital_name='Duke Hospital';
update hospitals
set hospital_code=50, location='Wahsington DC'
where hospital_name='Duke Hospital';
select * from hospitals;
-- DELETE , TRUNCATE
-- Difference between DELETE and TRUNCATE
--1) DELETE can either delete few records or all records but TRUNCATE ALWAYS REMOVES all data/records/rows.
--2) TRUNCATE is much faster than DELETE
select * from hospitals;
delete from hospitals
where hospital_code = 50;
truncate table hospitals;
drop table hospitals;
SQL for Beginners: A Complete Introduction to SQL Basics!
• SQL for Beginners: A Complete Introduction...
Master SQL Commands: DDL, Data Types & Constraints Explained!
• Master SQL Commands: DDL, Data Types & Con...
Mastering SQL Constraints: Primary Key, Unique Key, Not Null, and CHECK Explained!
• Mastering SQL Constraints: Primary Key, Un...
Understanding SQL Foreign Keys: Building Relationships Between Tables
• Understanding SQL Foreign Keys: Building R...
SQL Identity Column: Auto-Generating Unique Values for Your Tables
• SQL Identity Column: Auto-Generating Uniqu...
SQL DML & DDL Commands Explained | Insert, Update, Delete, Truncate, Drop
• SQL DML & DDL Commands Explained | Insert,...
Master Basic SQL Queries & Operators | Part 1: Fetch, Filter & Count
• Master Basic SQL Queries & Operators | Par...
SQL Functions and Queries: Aggregate, CAST, REPLACE, ROUND, GETDATE
• SQL Functions and Queries: Aggregate, CAST...
Mastering SQL INNER JOIN: Essential Queries & Examples
• Mastering SQL INNER JOIN: Essential Querie...
SQL Group By Explained with Examples | Master Aggregate Queries
• SQL Group By Explained with Examples | Mas...
Mastering SQL: Group By, Having, CASE, Order By, Join, Top, and Limit
• Mastering SQL: Group By, Having, CASE, Ord...
Introduction to SQL Normalization: 1NF (First Normal Form) - Part 1
• Introduction to SQL Normalization: 1NF (Fi...
Understanding SQL Normalization: 2NF (Second Normal Form) - Part 2
• Understanding SQL Normalization: 2NF (Seco...
Mastering SQL Normalization: 3NF (Third Normal Form) Explained - Part 3
• Mastering SQL Normalization: 3NF (Third No...
Master SQL Subqueries: Scalar, Multi-Row, and Correlated Subqueries Explained
• Master SQL Subqueries: Scalar, Multi-Row, ...
SQL Tutorial: Remove Duplicate Data Efficiently | Common Interview Question
• SQL Tutorial: Remove Duplicate Data Effici...
SQL Joins Explained: Master INNER, LEFT, RIGHT, FULL, CROSS & SELF Joins with Examples
• SQL Joins Explained: Master INNER, LEFT, R...
Master SQL Joins: Self Joins, Outer Joins, and More!
• Master SQL Joins: Self Joins, Outer Joins,...
SQL Queries Using CTE: Profitability & Monthly Sales Differences
• SQL Queries Using CTE: Profitability & Mon...
Calculate User Popularity Percentage with SQL CTEs
• Calculate User Popularity Percentage with ...
SQL Window Functions Explained: ROW_NUMBER, RANK & DENSE_RANK
• SQL Window Functions Explained: ROW_NUMBER...
SQL Window Functions Explained: LEAD & LAG with Real Examples!
• SQL Window Functions Explained: LEAD & LAG...
Master SQL Window Functions: FIRST_VALUE, LAST_VALUE, and More!
• Master SQL Window Functions: FIRST_VALUE, ...
Easily Delete Duplicate Rows in SQL Server with ROW_NUMBER()
• Easily Delete Duplicate Rows in SQL Server...
Understanding Recursive CTEs in SQL: A Simple Guide
• Understanding Recursive CTEs in SQL: A Sim...
Master SQL PIVOT: Transform Rows into Columns
• Master SQL PIVOT: Transform Rows into Columns
🔔 *Subscribe* for more in-depth SQL tutorials and tips!
#SQL #SQLTutorial #Database #SQLCommands #LearnSQL #SQLInsert #SQLUpdate #SQLDelete #SQLTruncate #SQLDrop