Skip to content

SQL

Basics

Create database

CREATE DATABASE dbName;

Delete database

DROP DATABASE dbname;

Create user

CREATE USER miriam WITH PASSWORD 'password' VALID UNTIL '2005-01-01';

Delete user

DROP USER username;

Delete table

DROP TABLE tablename;

Update field for table

UPDATE tablename SET COLUME WHERE CONDITION;

Update user's password

ALTER ROLE username WITH PASSWORD 'password';

Alter table column

ALTER TABLE Customers DROP COLUMN `ContactName`;

Show indexs

SHOW INDEXS FROM `TableName`

Create index

-- general
CREATE INDEX idx_name ON table(column);
ALTER TABLE table ADD INDEX idx_name(column);

-- unique
CREATE UNIQUE INDEX idx_name ON table(column);
ALTER TABLE table ADD UNIQUE INDEX idx_name(column);

Cleanup the table

TRUNCATE TABLE `TableName`;
Back to top