Comprehensive Overview of SQL Commands and Language Categories

 
อาจารย์สุรินทร์ทิพ ศักดิ์ภูวดล
สำนักเทคโนโลยีสารสนเทศและการสื่อสาร
มหาวิทยาลัยพะเยา
บทที่ 
3
ภาษา 
SQL
Structured Query Language(SQL)
Part 1
 
Update
            
Select
Delete
SQL CATEGORIES
 
  
SQL  Language 
เป็นภาษาที่ใช้จัดการโครงสร้าง และจัดการการข้อมูลที่จัดเก็บ
ในโปรแกรมที่เป็นตระกูล ระบบจัดการฐานข้อมูล
 (Database Management System:
DBMS) 
เช่น 
MS SQL Server, My SQL, MS Access
  
เราจะใช้ภาษา 
SQL
 ใน 
DBMS 
และใช้เขียนแทรกเพื่อจัดการข้อมูล ในการเขียน
โปรแกรมด้วยภาษาต่างๆ เช่น แทรกในภาษา 
PHP, 
แทรกในภาษา 
Visual basic
 
คำสั่ง 
SQL 
แบ่งเป็นหลายกลุ่ม เช่น
 
1. DDL
 
- Data Definition Language
 
2. DML
 
- Data Manipulation Language
 
3. DCL 
 
- Data Control Language
 
4. TCL 
 
- Transaction Control Language
SQL Command
Categories
CREATE
ALTER
DROP
TRUNCATE
COMMENT
RENAME
SELECT
INSERT
UPDATE
DELETE
MERGE
CALL
EXPLAIN PLAN
LOCK TABLE
 
GRANT
REVOKE
 
 
COMMIT
ROLLBACK
SAVEPOINT
SET TRANSACTION
 
 
https://www.w3schools.in/mysql/ddl-dml-dcl/
Data Definition Language (DDL)
 
Data Definition Language (DDL)  
เป็นคำสั่งในการจัดการโครงสร้างของ
ฐานข้อมูล เช่น เพิ่มตาราง 
(CREATE Table) , 
ลบตาราง 
(DROP Table)
CREATE : 
to create database and its objects like (table, index, views, store
procedure, function and triggers)  
(
สร้าง
)
ALTER : 
alters the structure of the existing database 
(
แก้ไข
)
DROP : 
delete objects from the database 
(
ลบ
)
TRUNCATE : 
remove all records from a table, including all spaces allocated
for the records are removed
COMMENT 
: 
add comments to the data dictionary
RENAME : 
rename an object
 
https://www.w3schools.in/mysql/ddl-dml-dcl/
 
  
Data Manipulation Language  (DML) 
จัดการข้อมูลในฐานข้อมูล
(Database)
SELECT – 
retrieve data from the a database
INSERT – 
insert data into a table
UPDATE – 
updates existing data within a table
DELETE – 
Delete all records from a database table
MERGE – 
UPSERT operation (insert or update)
CALL – 
call a PL/SQL or Java subprogram
EXPLAIN PLAN – 
interpretation of the data access path
LOCK TABLE – 
concurrency Control
Data Manipulation Language  (DML)
 
  
Data Control Language (DCL) 
เป็นการควบคุมการเข้าถึงข้อมูล
GRANT –
 
allow users access privileges to database
REVOKE 
withdraw users access privileges given by using the GRANT
command
Data Control Language (DCL)
 
  
Transaction Control Language (TCL) 
จัดการการประมวลผล
ข้อมูลในฐานข้อมูล
COMMIT – 
commits a Transaction 
เป็นการยืนยันการเปลี่ยนแปลงข้อมูล
ROLLBACK – 
rollback a transaction in case of any error occurs 
ดึงข้อมูล
เก่าก่อนหน้ากลับมา
SAVEPOINT – 
to rollback the transaction making points within groups
กำหนดจุดของข้อมูล ที่ให้ 
rollback 
ข้อมูลกลับมา
SET TRANSACTION – 
specify characteristics for the transaction 
เป็น
การกำหนดคุณสมบัติของ 
transaction
Transaction Control Language (TCL)
คำสั่ง 
Select
 
Select  field name /[*][Count(?)]
From   table name
[Where condition]
[Order by field name desc/asc]
 
Select Product_name
From  Product
Where Product_id
=‘G001’
 
Select *
From TPS_Product
Where Product_Id 
<>'G001‘
Order by field name desc
คำสั่ง 
Select
 
Select
 *
From
 TPS_Product
Where
 Product_Id  like '%001'
Order
 by Product_Id  asc
คำสั่ง 
Select
 
Select *
From
 TPS_Product
Where
 Product_Id = 'G001' and
Product_name like '%B%'
 
And = 
ข้อมูลที่ตรงเงื่อนไขทั้งสองอย่างจึงให้แสดงข้อมูล
 
Select
 *
From
 TPS_Product
Where
 Product_Id = 'G001' or
Product_Id = 'G002'
 
Or = 
ข้อมูลที่ตรงเงื่อนไขอย่างใดอย่างหนึ่งก็ให้แสดงข้อมูล
 
 
Select Branch_No, Product_Id, Date, SUM(Total_amount)
From 
Stage_SaleData
     group by DATE, Product_Id, Branch_No
คำสั่ง 
Select Built-in Function
Min (
น้อยสุด
), Max (
มากสุด
), AVG (
ค่าเฉลี่ย
),
Count (
จำนวนนับ
), Sum (
จำนวนรวม
)
 
Select count(Product_id)
From TPS_Product
 
Delete  from Table_Name
[Where condition]
 
Delete
From TPS_Product
 
(!!! 
คำสั่งนี้ จะลบ 
Table) 
พึงระวังเสมอ
 
 
Delete
From TPS_Product
Where Product_id='G001'
คำสั่ง 
Delete
 
Update
 TableName
Set
 FieldName=Value
[Where condition]
 
Update
 Product
Set
 Product_Name='Water'
 
(!!! 
คำสั่งนี้จะแก้ไขทั้ง 
Table) 
พึงระวังเสมอ
 
Update
 Product
Set
 Product_Name='Water'
Where
 Product_id='G001'
คำสั่ง 
Delete
 
Reference
 
https://www.w3schools.in/mysql/ddl-dml-dcl/
Slide Note
Embed
Share

In this detailed guide, you will learn about Structured Query Language (SQL) including its various commands such as Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), and Transaction Control Language (TCL). Explore how SQL is used in Database Management Systems like MS SQL Server, MySQL, and MS Access, covering aspects such as creating, updating, deleting data, granting access privileges, transaction management, and more.

  • SQL
  • Command Categories
  • DDL
  • DML
  • Database Management
  • DBMS

Uploaded on Aug 14, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. 3 SQL

  2. Structured Query Language(SQL) Part 1 Update Select Delete

  3. SQL CATEGORIES SQL Language (Database Management System: DBMS) MS SQL Server, My SQL, MS Access SQL DBMS PHP, Visual basic SQL 1. DDL 2. DML 3. DCL 4. TCL -Data Definition Language -Data Manipulation Language -Data Control Language -Transaction Control Language

  4. SQL Command Categories DDL DML DCL TCL GRANT REVOKE SELECT INSERT UPDATE DELETE MERGE CALL EXPLAIN PLAN LOCK TABLE COMMIT ROLLBACK SAVEPOINT SET TRANSACTION CREATE ALTER DROP TRUNCATE COMMENT RENAME https://www.w3schools.in/mysql/ddl-dml-dcl/

  5. Data Definition Language (DDL) Data Definition Language (DDL) (CREATE Table) , (DROP Table) CREATE : to create database and its objects like (table, index, views, store procedure, function and triggers) ( ) ALTER : alters the structure of the existing database ( ) DROP : delete objects from the database ( ) TRUNCATE : remove all records from a table, including all spaces allocated for the records are removed COMMENT : add comments to the data dictionary RENAME : rename an object https://www.w3schools.in/mysql/ddl-dml-dcl/

  6. Data Manipulation Language (DML) Data Manipulation Language (DML) (Database) SELECT retrieve data from the a database INSERT insert data into a table UPDATE updates existing data within a table DELETE Delete all records from a database table MERGE UPSERT operation (insert or update) CALL call a PL/SQL or Java subprogram EXPLAIN PLAN interpretation of the data access path LOCK TABLE concurrency Control

  7. Data Control Language (DCL) Data Control Language (DCL) GRANT allow users access privileges to database REVOKE withdraw users access privileges given by using the GRANT command

  8. Transaction Control Language (TCL) Transaction Control Language (TCL) COMMIT commits a Transaction ROLLBACK rollback a transaction in case of any error occurs SAVEPOINT to rollback the transaction making points within groups rollback SET TRANSACTION specify characteristics for the transaction transaction

  9. Select Select field name /[*][Count(?)] From table name [Where condition] [Order by field name desc/asc] Desc Asc Select Product_name From Product Where Product_id= G001 Select * From TPS_Product Where Product_Id <>'G001 Order by field name desc

  10. Select Select * From TPS_Product Where Product_Id like '%001' Order by Product_Id asc

  11. Select Select * From TPS_Product Where Product_Id = 'G001' or Product_Id = 'G002' Or = Select * From TPS_Product Where Product_Id = 'G001' and Product_name like '%B%' And =

  12. Select Built-in Function Min ( ), Max ( ), AVG ( ), Count ( ), Sum ( ) Select count(Product_id) From TPS_Product Select Branch_No, Product_Id, Date, SUM(Total_amount) From Stage_SaleData group by DATE, Product_Id, Branch_No

  13. Delete Delete from Table_Name [Where condition] Delete From TPS_Product (!!! Table) Delete From TPS_Product Where Product_id='G001'

  14. Delete Update TableName Set FieldName=Value [Where condition] Update Product Set Product_Name='Water' (!!! Table) Update Product Set Product_Name='Water' Where Product_id='G001'

  15. Reference https://www.w3schools.in/mysql/ddl-dml-dcl/

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#