Mysql/CheatSheet: Difference between revisions
< Mysql
(→Tables) |
No edit summary |
||
Line 24: | Line 24: | ||
<blockquote> | <blockquote> | ||
<pre> | <pre> | ||
SHOW | SHOW DATABASES; | ||
</pre> | </pre> | ||
</blockquote> | </blockquote> |
Revision as of 15:27, 15 June 2020
Databases
- Create
CREATE DATABASE [IF NOT EXISTS] database_name;
- Use
USE database_name;
- Delete
DROP DATABASE [IF EXISTS] database_name;
- List all
SHOW DATABASES;
- Storage Engines
- MyISAM (optimized for compression and speed. portable. not transaction safe. used to be default)
- InnoDB (optimized for speed. portable. portable. default)
- MERGE
- MEMORY (HEAP)
- ARCHIVE
- CSV
- FEDERATED
Tables
- list
SHOW TABLES;
- create
CREATE TABLE [IF NOT EXISTS] table_name( column1 datatype constraint, column2 datatype constraint );
CREATE TABLE IF NOT EXISTS cars( vehicle_id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255) NOT NULL, first_seen DATE, description TEXT );
- constraints
- NOT NULL
- UNIQUE
- PRIMARY KEY (NOT NULL and UNIQUE)
- FOREIGN KEY
- CHECK
- DEFAULT
- INDEX