0% found this document useful (0 votes)
4 views2 pages

MySQL Commands CheatSheet

The document provides a comprehensive overview of MySQL commands, including syntax and examples for database, table, index, view, and stored procedure operations. It covers commands for querying, modifying data, and joining tables, along with searching techniques. Each section includes specific commands and their formats for effective database management.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

MySQL Commands CheatSheet

The document provides a comprehensive overview of MySQL commands, including syntax and examples for database, table, index, view, and stored procedure operations. It covers commands for querying, modifying data, and joining tables, along with searching techniques. Each section includes specific commands and their formats for effective database management.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

MySQL Commands - Syntax and Examples

Database Commands
CREATE DATABASE IF NOT EXISTS db_name;
USE db_name;
DROP DATABASE IF EXISTS db_name;
SHOW DATABASES;

Table Commands
CREATE TABLE [IF NOT EXISTS] table_name (
column_name1 datatype,
column_name2 datatype,
...
);
SHOW TABLES;
INSERT INTO table_name (column1, column2) VALUES (value1, value2);
ALTER TABLE table_name ADD column_name datatype;
ALTER TABLE table_name DROP column_name;
DROP TABLE IF EXISTS table_name;

Index Commands
CREATE INDEX index_name ON table_name (column1, column2);
DROP INDEX index_name ON table_name;
CREATE UNIQUE INDEX index_name ON table_name (column1, column2);

View Commands
CREATE VIEW IF NOT EXISTS view_name AS
SELECT column1, column2 FROM table_name WHERE condition;
DROP VIEW IF EXISTS view_name;
RENAME TABLE view_name TO new_view_name;

Stored Procedure Commands


DELIMITER $$
CREATE PROCEDURE procedure_name (parameter_list)
BEGIN
-- procedure body
END $$
DELIMITER ;
CALL procedure_name;
DROP PROCEDURE IF EXISTS procedure_name;

Querying Data
SELECT * FROM table_name;
SELECT column1, column2 FROM table_name;
MySQL Commands - Syntax and Examples

SELECT DISTINCT column_name FROM table_name;


SELECT column1, column2 FROM table_name WHERE condition;

Joining Tables
SELECT t1.col1, t2.col2
FROM table1 t1
INNER JOIN table2 t2 ON t1.id = t2.id;
SELECT t1.col1, t2.col2
FROM table1 t1
LEFT JOIN table2 t2 ON t1.id = t2.id;
SELECT t1.col1, t2.col2
FROM table1 t1
RIGHT JOIN table2 t2 ON t1.id = t2.id;
SELECT * FROM table1 CROSS JOIN table2;

Modifying Data
INSERT INTO table_name (column1, column2) VALUES (value1, value2);
UPDATE table_name SET column1 = value1 WHERE condition;
DELETE FROM table_name WHERE condition;

Searching
SELECT * FROM table_name WHERE column_name LIKE '%pattern%';
SELECT * FROM table_name WHERE column_name RLIKE 'regex_pattern';

You might also like