Show Menu
Cheatography

MySQL Cheat Sheet Cheat Sheet (DRAFT) by

A comprehensive SQL CS according to a Student

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Introd­uction

SQL or Structured Query Language is a computer language for storing, manipu­lating and retrieving data stored in relational database.
It works on a 3 level system of Relational Database Management System:
It is broadly divided into SQL+ and PL/SQL
SQL+ is then divided into many languages:
  1.DDL - Data Definition Language
  2. DML - Data Manipu­lation Language
  3. DCL - Data Control Language
  4. TCL - Transa­ction Control Language

Introd­uction

SQL or Structured Query Language is a computer language for storing, manipu­lating and retrieving data stored in relational database.
It works on a 3 level system of Relational Database Management System: External View (Defines the layer visible to every user of the database), Conceptual View (Defines the layer that makes the logic for the entire database) and Physical View (Defines the layer of physical storage of data)

Creating and using a database

CREATE <Database Name>;

USE <Database Name>;

Creating a Table

CREATE TABLE <TableName>(Attributes);

Inserting values into a Table

Attributes are created with a set data type: int, number, float, char, varchar, date

INSERT INTO <TableName> VALUES (Att1,Att2),(Att1, Att2),(Att1, Att2);
This will only work if the input values are of the same data type given while creating the table.
 

Relation, Entities and Attributes

An Entity is any real world object that could be explained through proper­ties.
Attributes are properties associated with every entity that gives the entity a character.
An entity with attributes that cannot uniquely identify it in the relation is called a weak entity set.
In terms of a table, an attribute is a column and every row is an entity.
A relation is the set of entities with many attrib­utes. It could be a weak relati­onship set, if the entities in the relation are weak.