Skip to content

Instantly share code, notes, and snippets.

@ryumada
Last active October 5, 2021 01:50
Show Gist options
  • Save ryumada/52576a93f90f1dc7c0d12157fbe1a896 to your computer and use it in GitHub Desktop.
Save ryumada/52576a93f90f1dc7c0d12157fbe1a896 to your computer and use it in GitHub Desktop.
My SQL Cheatsheet

This does not contain a common SQL Query, maybe I will add it in the future. it still just contains any command that is commonly used via terminal/console.

Table of contents:


Add Column to table

ALTER TABLE items ADD COLUMN stock INT;

add stock column to items table


Change the name of the attribute and its type.

ALTER TABLE items CHANGE COLUMN price cost INT;

change on the items table attribute named price to cost as INT.


Create a table

mysql> CREATE TABLE users (`id` int auto_increment, `name` text, primary key (id));

code above is an example to create a users table, and then inside () is a table structure.


Delete a database

DROP DATABASE database_name;

remove a database.


Delete a table

DROP TABLE table_name;

remove a table.


Delete an attribute / column

ALTER TABLE items DROP COLUMN category;

delete category column from the items table.


Login to enter MySQL System

mysql --user=root --password

--user=root can be anything based on your system configured after that.


Show Databases

mysql> SHOW databases;

show the databases created in the system.


Show Tables

mysql> SHOW tables;

show all tables inside a database.


Update table entity / row value

UPDATE users SET username='ryumada' WHERE username='rizukiRyumada';

update username to ryumada, into a user that has username rizukiRyumada


Using a Database to start to create and run queries

USE table_name;

Change table_name with the table name you want to change.

View the structure of a table

DESCRIBE users;

describe the structure of the users table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment