Загрузил den.gokhveys

Базовые SQL-запросы

Реклама
Data Definition Language (DDL)
DDL statements are used to define, alter, and manage the schema and structure of the database.
CREATE
CREATE DATABASE database_name; Creates a new database.
CREATE TABLE table_name (...); Creates a new table in the database.
ALTER
ALTER TABLE table_name ADD column_name datatype; Adds a new column to a table.
ALTER TABLE table_name DROP COLUMN column_name; Deletes a column from a table.
ALTER TABLE table_name MODIFY COLUMN column_name datatype; Changes the data type
of a column.
DROP
DROP TABLE table_name; Deletes a table and its data permanently.
DROP DATABASE database_name; Deletes a database and its contents.
TRUNCATE
TRUNCATE TABLE table_name; Removes all records from a table without deleting the table
itself.
Data Manipulation Language (DML)
DML statements are used for managing data within table objects.
SELECT
SELECT column1, column2, ... FROM table_name; Retrieves data from one or more columns of
a table.
SELECT * FROM table_name; Retrieves all columns from a table.
INSERT
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...); Inserts new
data into a table.
UPDATE
UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition; Updates
data in a table.
DELETE
DELETE FROM table_name WHERE condition; Deletes records from a table based on a
condition.
Data Control Language (DCL)
DCL statements include commands regarding permissions and security of database objects.
GRANT
GRANT privilege_type ON database_name.table_name TO 'username'@'hostname'; Allows
specific user access privileges to a database table.
REVOKE
REVOKE privilege_type ON database_name.table_name FROM 'username'@'hostname';
Removes specific user access privileges.
Transaction Control Language (TCL)
TCL commands manage changes affecting the data.
COMMIT
COMMIT; Makes all changes made during the transaction permanent.
ROLLBACK
ROLLBACK; Undoes changes since the last COMMIT.
SAVEPOINT
SAVEPOINT savepoint_name; Sets a savepoint within a transaction which you can rollback to.
Additional Utility Statements
COMMENT
COMMENT ON TABLE table_name IS 'your_comment'; Adds a comment to a table definition.
SHOW
SHOW DATABASES; Lists all databases on the database server.
SHOW TABLES; Lists all tables in the current database.
Скачать