Chủ Nhật, 23 tháng 7, 2023

SQL Quick Reference

Mục đích: Chia sẻ nhanh câu lệnh SQL

SQL Statement

Syntax

AND / OR

SELECT column_name(s)

FROM table_name

WHERE condition

AND|OR condition

ALTER TABLE

ALTER TABLE table_name

ADD column_name datatype

or

ALTER TABLE table_name

DROP COLUMN column_name

AS (alias)

SELECT column_name AS column_alias

FROM table_name

or

SELECT column_name

FROM table_name  AS table_alias

BETWEEN

SELECT column_name(s)

FROM table_name

WHERE column_name

BETWEEN value1 AND value2

CREATE DATABASE

CREATE DATABASE database_name

CREATE TABLE

CREATE TABLE table_name

(

column_name1 data_type,

column_name2 data_type,

column_name3 data_type,

...

)

CREATE INDEX

CREATE INDEX index_name

ON table_name (column_name)

or

CREATE UNIQUE INDEX index_name

ON table_name (column_name)

CREATE VIEW

CREATE VIEW view_name AS

SELECT column_name(s)

FROM table_name

WHERE condition

DELETE

DELETE FROM table_name

WHERE some_column=some_value

or

DELETE FROM table_name

(Note: Deletes the entire table!!)

DELETE * FROM table_name

(Note: Deletes the entire table!!)

DROP DATABASE

DROP DATABASE database_name

DROP INDEX

DROP INDEX table_name.index_name (SQL Server)

DROP INDEX index_name ON table_name (MS Access)

DROP INDEX index_name (DB2/Oracle)

ALTER TABLE table_name

DROP INDEX index_name (MySQL)

DROP TABLE

DROP TABLE table_name

EXISTS

IF EXISTS (SELECT * FROM table_name WHERE id = ?)

BEGIN

--do what needs to be done if exists

END

ELSE

BEGIN

--do what needs to be done if not

END

GROUP BY

SELECT column_name, aggregate_function(column_name)

FROM table_name

WHERE column_name operator value

GROUP BY column_name

HAVING

SELECT column_name, aggregate_function(column_name)

FROM table_name

WHERE column_name operator value

GROUP BY column_name

HAVING aggregate_function(column_name) operator value

IN

SELECT column_name(s)

FROM table_name

WHERE column_name

IN (value1,value2,..)

INSERT INTO

INSERT INTO table_name

VALUES (value1, value2, value3,....)

or

INSERT INTO table_name

(column1, column2, column3,...)

VALUES (value1, value2, value3,....)

INNER JOIN

SELECT column_name(s)

FROM table_name1

INNER JOIN table_name2

ON table_name1.column_name=table_name2.column_name

LEFT JOIN

SELECT column_name(s)

FROM table_name1

LEFT JOIN table_name2

ON table_name1.column_name=table_name2.column_name

RIGHT JOIN

SELECT column_name(s)

FROM table_name1

RIGHT JOIN table_name2

ON table_name1.column_name=table_name2.column_name

FULL JOIN

SELECT column_name(s)

FROM table_name1

FULL JOIN table_name2

ON table_name1.column_name=table_name2.column_name

LIKE

SELECT column_name(s)

FROM table_name

WHERE column_name LIKE pattern

ORDER BY

SELECT column_name(s)

FROM table_name

ORDER BY column_name [ASC|DESC]

SELECT

SELECT column_name(s)

FROM table_name

SELECT *

SELECT *

FROM table_name

SELECT DISTINCT

SELECT DISTINCT column_name(s)

FROM table_name

SELECT INTO

SELECT *

INTO new_table_name [IN externaldatabase]

FROM old_table_name

or

SELECT column_name(s)

INTO new_table_name [IN externaldatabase]

FROM old_table_name

SELECT TOP

SELECT TOP number|percent column_name(s)

FROM table_name

TRUNCATE TABLE

TRUNCATE TABLE table_name

UNION

SELECT column_name(s) FROM table_name1

UNION

SELECT column_name(s) FROM table_name2

UNION ALL

SELECT column_name(s) FROM table_name1

UNION ALL

SELECT column_name(s) FROM table_name2

UPDATE

UPDATE table_name

SET column1=value, column2=value,...

WHERE some_column=some_value

WHERE

SELECT column_name(s)

FROM table_name

WHERE column_name operator value


=============================
* KHOÁ HỌC ORACLE DATABASE A-Z ENTERPRISE trực tiếp từ tôi giúp bạn bước đầu trở thành những chuyên gia DBA, đủ kinh nghiệm đi thi chứng chỉ OA/OCP, đặc biệt là rất nhiều kinh nghiệm, bí kíp thực chiến trên các hệ thống Core tại VN chỉ sau 1 khoá học.
* CÁCH ĐĂNG KÝ: Gõ (.) hoặc để lại số điện thoại hoặc inbox https://m.me/tranvanbinh.vn hoặc Hotline/Zalo 090.29.12.888
* Chi tiết tham khảo:
https://bit.ly/oaz_w
=============================
KẾT NỐI VỚI CHUYÊN GIA TRẦN VĂN BÌNH:
📧 Mail: binhoracle@gmail.com
☎️ Mobile/Zalo: 0902912888
👨 Facebook: https://www.facebook.com/BinhOracleMaster
👨 Inbox Messenger: https://m.me/101036604657441 (profile)
👨 Fanpage: https://www.facebook.com/tranvanbinh.vn
👨 Inbox Fanpage: https://m.me/tranvanbinh.vn
👨👩 Group FB: https://www.facebook.com/groups/DBAVietNam
👨 Website: https://www.tranvanbinh.vn
👨 Blogger: https://tranvanbinhmaster.blogspot.com
🎬 Youtube: https://www.youtube.com/@binhguru
👨 Tiktok: https://www.tiktok.com/@binhguru
👨 Linkin: https://www.linkedin.com/in/binhoracle
👨 Twitter: https://twitter.com/binhguru
👨 Podcast: https://www.podbean.com/pu/pbblog-eskre-5f82d6
👨 Địa chỉ: Tòa nhà Sun Square - 21 Lê Đức Thọ - Phường Mỹ Đình 1 - Quận Nam Từ Liêm - TP.Hà Nội

=============================
oracle tutorial, học oracle database, Tự học Oracle, Tài liệu Oracle 12c tiếng Việt, Hướng dẫn sử dụng Oracle Database, Oracle SQL cơ bản, Oracle SQL là gì, Khóa học Oracle Hà Nội, Học chứng chỉ Oracle ở đầu, Khóa học Oracle online,sql tutorial, khóa học pl/sql tutorial, học dba, học dba ở việt nam, khóa học dba, khóa học dba sql, tài liệu học dba oracle, Khóa học Oracle online, học oracle sql, học oracle ở đâu tphcm, học oracle bắt đầu từ đâu, học oracle ở hà nội, oracle database tutorial, oracle database 12c, oracle database là gì, oracle database 11g, oracle download, oracle database 19c, oracle dba tutorial, oracle tunning, sql tunning , oracle 12c, oracle multitenant, Container Databases (CDB), Pluggable Databases (PDB), oracle cloud, oracle security, oracle fga, audit_trail,oracle RAC, ASM, oracle dataguard, oracle goldengate, mview, oracle exadata, oracle oca, oracle ocp, oracle ocm , oracle weblogic, postgresql tutorial, mysql tutorial, mariadb tutorial, ms sql server tutorial, nosql, mongodb tutorial, oci, cloud, middleware tutorial, hoc solaris tutorial, hoc linux tutorial, hoc aix tutorial, unix tutorial, securecrt, xshell, mobaxterm, putty

ĐỌC NHIỀU

Trần Văn Bình - Oracle Database Master