Skip to content

Latest commit

 

History

History
89 lines (69 loc) · 2.47 KB

README.md

File metadata and controls

89 lines (69 loc) · 2.47 KB

SQL_LOG

HELLO!This is my SQL skillset! Recording What I learnd about SQL. TBC

DATABASE

CREATE DATABASE

CREATE DATABASE database_name

ALTER DATABASE

ALTER DATABASE database_name RENAME TO new_name

DEOP DATABASE

DROP DATABASE database_name

TABLE

CREATE TABLE

CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype,....);

DROP TABLE

DROP TABLE table_name;

ALTER TABLE

Add column:ALTER TABLE table_name ADD column_name datatype;
Drop column:ALTER TABLE table_name DROP COLUMN column_name;
Rename column: ALTER TABLE table_name RENAME COLUMN old_name To new_name;
Change column datatype: ALTER TABLE table_name MODIFY COLUMN column_name datatype;

CONSTRAINTS

Constraints can be specified when the table is created with the CREATE TABLE statement, or after the table is created with the ALTER TABLE statement.
CREATE TABLE table_name (
column1 datatype constraint,
column2 datatype constraint,
column3 datatype constraint,...);


The following constraints are commonly used in SQL:
NOT NULL: Ensures that a column cannot have a NULL value
UNIQUE: Ensures that all values in a column are different
PRIMARY KEY: A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a table
FOREIGN KEY: Prevents actions that would destroy links between tables
CHECK: Ensures that the values in a column satisfies a specific condition
DEFAULT: Sets a default value for a column if no value is specified

INSERT VALUE INTO TABLE

INSERT INTO table_name (column1, column2, column3, ...)VALUES (value1, value2, value3, ...);

UNDATE TABLE

UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;

DELETE

DELETE FROM table_name WHERE condition;

SELECT QUERY COMMANDS

SELECT

SELECT column1, column2, ...FROM table_name;
SELECT * FROM table_name;
SELECT COUNT() FROM table_name;
SELECT DISTINCT() FROM table_name;

SELECT...WHERE

SELECT column1, column2, ...
FROM table_name
WHERE condition;

WHERE condition:

AND: WHERE condition1 AND condition2 AND condition3 ...;
OR: WHERE condition1 OR condition2 OR condition3 ...;
NOT:WHERE NOT condition;
OTHERS:=,>,<,>=,<=,<>,BETWEEN...AND...,LIKE,IN

SELECT...ORDER BY...

SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;

SQL FUNCTIONS