100% found this document useful (1 vote)
73 views

SQL Cheatsheet PDF

This document provides a summary of SQL concepts including: 1) SQL commands are divided into DDL, DML, and DCL categories for defining schemas, manipulating data, and controlling permissions respectively. 2) Common data types include integers, strings, text, and timestamps. Tables can be joined using left, right, inner, and cartesian joins. 3) Indexes improve search speed but increase insert/update time by indexing one or more columns. The SELECT statement is used to query data with options for filtering, aggregation, sorting, and common keywords.

Uploaded by

jairus 313
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
73 views

SQL Cheatsheet PDF

This document provides a summary of SQL concepts including: 1) SQL commands are divided into DDL, DML, and DCL categories for defining schemas, manipulating data, and controlling permissions respectively. 2) Common data types include integers, strings, text, and timestamps. Tables can be joined using left, right, inner, and cartesian joins. 3) Indexes improve search speed but increase insert/update time by indexing one or more columns. The SELECT statement is used to query data with options for filtering, aggregation, sorting, and common keywords.

Uploaded by

jairus 313
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

SQL Cheatsheet

Joins
What is SQL?
Structured Query Language or SQL is a
standard Database language which is used to
create, maintain and retrieve the relational
database

Types of SQL Commands


Left Join Right Join Inner Join Cartesian Join
 DDL - Define the schema of database or
its objects (like tables and indexes) (Ex -
CREATE, ALTER, DROP) What is an index?
 DML - Manipulate and Select data in the Inserting data in a table
database (Ex – SELECT, INSERT)  Data structure that
 DCL - Rights, permissions and other INSERT INTO<tableName> improves the speed of
controls of the database system (Ex – (column1, column2, column3, ...) operations in a table.
GRANT, REVOKE)  Indexes can be created
VALUES (value1, value2,
value3, ...); using one or more
Most Common Datatypes columns
• int(10)
• varchar(255)
Basic Query Syntax  Indexing a column
• text improves search but
• TIMESTAMP SELECT f(col1), g(col2),… from increases the time for
• ENUM (’Choice1’, ‘Choice2’, …) table1 insert and update
---filter the rows
Importing and Exporting data from WHERE col2=1 and col5=4 Creating an Index
CSV ---Aggregate the data create index <index_name>
GROUPBY .. on <table> (<Column to
Importing data from CSV - LOAD --- Filter the results Index>)
DATA LOCAL INFILE <full_file_path> HAVING h(col4)>=<…
INTO TABLE <tableName> --- Sort the results
COLUMNS TERMINATED BY ',’ ORDER BY col2
OPTIONALLY ENCLOSED BY '” ESCAPED
BY '"' f, g, h are aggregation functions
LINES TERMINATED BY '\n’ like
IGNORE 1 LINES; COUNT(*), COUNT(DISTINCT),
SUM(), STDDEV() etc
Exporting data to CSV - SELECT *
INTO OUTFILE <outputFilePath> Other useful Keywords which
FIELDS TERMINATED BY ',' OPTIONALLY work with SELECT
ENCLOSED BY '"' DISTINCT
LINES TERMINATED BY '\n' FROM LIKE
<tableName>; BETWEEN
IN
Creating a table Syntax
CREATE TABLE <tableName> (

<fieldname1><fieldtype1>
(NULL/NNOT NULL) ,
<fieldname2><fieldtype2>
);

You might also like