{"id":20499192,"url":"https://github.com/mohdnehalkhan/mysql-commands","last_synced_at":"2026-04-29T14:36:26.604Z","repository":{"id":242806883,"uuid":"809246490","full_name":"MOHDNEHALKHAN/MYSQL-COMMANDS","owner":"MOHDNEHALKHAN","description":"Repository contains all commands of MYSQL used in our day to day work in MYSQL DB","archived":false,"fork":false,"pushed_at":"2024-06-05T03:58:34.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-16T06:58:01.900Z","etag":null,"topics":["database","dbms","mysql","mysql-database","sql"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MOHDNEHALKHAN.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-02T06:17:13.000Z","updated_at":"2024-06-05T03:58:37.000Z","dependencies_parsed_at":"2024-06-05T04:55:29.058Z","dependency_job_id":"8048a5e4-194e-4f79-9303-353214c8eaab","html_url":"https://github.com/MOHDNEHALKHAN/MYSQL-COMMANDS","commit_stats":null,"previous_names":["mohdnehalkhan/mysql-commands"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MOHDNEHALKHAN%2FMYSQL-COMMANDS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MOHDNEHALKHAN%2FMYSQL-COMMANDS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MOHDNEHALKHAN%2FMYSQL-COMMANDS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MOHDNEHALKHAN%2FMYSQL-COMMANDS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MOHDNEHALKHAN","download_url":"https://codeload.github.com/MOHDNEHALKHAN/MYSQL-COMMANDS/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242089146,"owners_count":20069919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","dbms","mysql","mysql-database","sql"],"created_at":"2024-11-15T18:16:45.412Z","updated_at":"2026-04-29T14:36:21.580Z","avatar_url":"https://github.com/MOHDNEHALKHAN.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# MYSQL CHEATSHEET\n\n|                                              COMMANDS |                                            THEIR USES |\n| --- | --- |\n| `CREATE DATABASE db-name`   **or**  `create database db-name` | It will create a database |\n| `CREATE DATABASE IF NOT EXITS db-name`    | It will create a database only if there is no other database of that same name |\n| `DROP DATABASE db-name`   **or**  `drop database db-name` | It will help to delete the database |\n| `DROP DATABASE IF NOT EXITS db-name` | It will delete database only if there is no other database of that same name |\n| `USE db-name`    | It will start using the specified database i.e. now you can create tables in the selected database |\n| `SHOW DATABASES;` | It will show all the databases in the system |\n| `SHOW TABLES;` | It will show all the tables in a selected database |\n| `DROP TABLE table-name`   **or**  `drop table table-name` | It will help to delete a table in a database |\n| `CREATE TABLE table-name (                       column_name1 datatype constraint ,               column_name2 datatype constraint,                 column_name3 datatype constraint                      );` | This query is used to create a table in the selected database |\n| `INSERT INTO  table_name VALUES( PARAMETERS);`  **or**                  `INSERT INTO table_name (column 1 , column 2)` | It will add data into the selected table |\n| `SELECT * FROM table_name` | It will retrieve all the data of the selected table` |\n| `SELECT * FROM table_name                           WHERE \u003ccondition_to_satisfy\u003e;` | It will retrieve all the data of the row that will satisfy the condition |\n| `UPDATE table_name                                    SET col1 = val1, col2 = val2                        WHERE condition;` | It will update the values of selected columns |\n| `DELETE FROM table_name  WHERE condition;`  | It will delete the entire row that will satisfy the condition |\n| `ALTER TABLE table_name ADD COLUMN coulmn_name datatype constraint;` | It will add a new column in your table |\n| `ALTER TABLE table_name DROP COLUMN coulmn_name ;` | It will delete the complete table from the database |\n| `ALTER TABLE table_name RENAME TO new_table_name;` | the table's name will be changed from old_table to new_table, |\n| `ALTER TABLE table_name  CHANGE COLUMN old_name new_name new_datatype new_constraint;` | It will change the name of the old column in the table |\n| `ALTER TABLE table_name                               MODIFY coulmn_name new_datatype new_constraint;` | It will update the data type or size of old column |\n| `ALTER TABLE table_name                               TRUNCATE COLUMN table_name;` | This command will remove the specified column from the table.  |\n|`SELECT column(s) FROM tableA INNER JOIN tableB ON tableA.col_name = table.col_name;` | It returns all rows from multiple tables where the join condition is satisfied.It is the mostcommon type of join.|\n| `SELECT column(s)FROM  tableA LEFT JOIN tableB    ON tableA.col_name = table.col_name;` | It returns all rows from the left-hand table specified in the ON condition and only those rows from the other table where the join condition is fulfilled. |\n| `SELECT column(s)                                    FROM tableA                                         RIGHT JOIN tableB                                      ON tableA.col_name = table.col_name;` | It returns all rows from the right-hand table specified in the ON condition and only those rowsfrom the other table where the join condition is satisfied |\n| `SELECT column(s)     FROM table as a                                        JOIN table as b                                        ON a.col_name = b.col_name;` | In this join, table is joined with itself |\n| `SELECT * FROM tableA as a                           LEFT JOIN tableB as b                                  ON a.id = b.id                                      UNION                                              SELECT * FROM tableA as a                           RIGHT JOIN tableB as b                                 ON a.id = b.id;` | It combines the results of both left and right outer joins |\n| `SELECT column(s)                                    FROM table_name                                     WHERE col_name operator                      (Subquery);` | It will retrieve data of selected columns that will satisfy the condition` |\n| `CREATE VIEW  view1 AS                             SELECT parameters FROM table_name` | It is to create a database view named view1 that presents data from the specified table_name using the SELECT statement provided. |\n| `Desc table_name;` | It allows you to see the table structure |\n| `Select No.1 + No.2;` | It will add two numbers |\n| `Select No.1 - No.2;` | It will subtract the second number from first |\n| `Select No.1 * No.2;` | It will give the product of supplied numbers |\n| `Select No.1/No.2;` | It will divide the number |\n| `Select \u003cco11\u003e, \u003ccol2\u003eFrom table_name Where value1 Between value2;` | It will only retrieve data of those columns whose values will fall between value1 and value2 (both inclusive) |\n| `Select * from table_nameWhere column_name IN (val1,val2,val3);` |Condition Based on a List |\n| `\"Select * from table_nameWhere column_name NOT IN (val1,val2,val3);”` | Condition Based on a List |\n| `Select Char(72,97,114,114,121);` | It returns the character for each integer passed |\n| `Select Concat(\"Nehal\",\"Khan\");` | It concatenates two strings |\n| `Select Lower(\"Brother\");` | It converts a string into lowercase |\n| `Select Upper(\"nehal\");` | It converts a string into uppercase |\n| `Select Substr(string,m,n);` | It extracts a substring from a given string |\n| `Select Trim(leading ' ' FROM ' Harry Bhai');` | It removes leading and trailing spaces from a given string |\n| `Select Instr(String1,String2);` | It searches for given second string into the given first string |\n| `Select Length(String)` | It returns the length of given string in bytes |\n| `Select MOD(11,4);` | It returns modulus of two numbers |\n| `Select Power(m,n);` | It returns the number m raised to the nth power |\n| `Select Round(15.193,1);` | It returns a number rounded off number |\n| `Select Sqrt(144);` | It returns the square root of a given number |\n| `Select Truncate(15.75,1);` | It returns a number with some digits truncated |\n| `Select Curdate();` | It returns the current date |\n| `Select Date('2021-12-10 12:00:00');` | It extracts the date part of the expression |\n| `Select Month(date);` | It returns the month from the date passed |\n| `Select Day(date);` | It returns the day part of a date |\n| `Select Year(date);` | It returns the year part of a date |\n| `Select now();` | It returns the current date and time |\n| `Select sysdate();` | It returns the time at which function executes |\n| `Select AVG(\u003ccolumn_name\u003e) \"Alias Name\" from \u003ctable_name\u003e;` | It calculates the average of given data |\n| `Select Count(\u003ccolumn_name\u003e) \"Alias Name\" from \u003ctable_name\u003e;` | It counts the number of rows in a given column |\n| `Select Max(\u003ccolumn_name\u003e) \"Alias Name\" from \u003ctable_name\u003e;` | It returns the maximum value from a given column |\n| `Select Min(\u003ccolumn_name\u003e) \"Alias Name\" from \u003ctable_name\u003e;` | It returns the minimum value from a given column |\n| `Select Sum(\u003ccolumn_name\u003e) \"Alias Name\" from \u003ctable_name\u003e;` | It returns the sum of values in given column |\n| `Select \u003ccolumn\u003e, Count(*) from \u003ctable_name\u003e group by \u003ccolumn\u003e;` | It allows you to group two or more columns and then you can perform aggregate function on them |\n| `Select avg(\u003ccolumn\u003e), sum(\u003ccolumn\u003e) from \u003ctable_name\u003e group by \u003ccolumn_name\u003e` | Having clause is used to put conditions on groups |\n| `Create table \u003ctable_name\u003e( col1 data_type NOT NULL,col2 data_type,col3 data_type);` | It will create a table with NOT NULL constraint to its first column |\n| `Create table table_name( col1 data_type DEFAULT 50,col2 data_type,col3 data_type);` | DEFAULT constraint provides a default value to a column |\n| `Create table table_name( col1 data_type UNIQUE,col2 data_type,col3 data_type);` | UNIQUE constraint ensures that all values in the column are different |\n| `Create table table_name( col1 data_type CHECK (condition),col2 data_type,col3 data_type);` | CHECK constraint ensures that all values in a column satisfy certain conditions |\n| `Create table table_name( col1 data_type Primary Key,col2 data_type,col3 data_type);` | Primary key is used to uniquely identify each row in a table |\n| `CREATE TABLE Orders (OrderID int NOT NULL, OrderNumber int NOT NULL,PersonID int, PRIMARY KEY (OrderID), FOREIGN KEY (PersonID) REFERENCES Persons(PersonID));` | Foreign key is used to link data from another table |\n| `Create table \u003ctable_name\u003e( col1 data_type NOT NULL,col2 data_type,col3 data_type);` | It will create a table with NOT NULL constraint to its first column |\n| `Create table table_name( col1 data_type DEFAULT 50,col2 data_type,col3 data_type);` | DEFAULT constraint provides a default value to a column |\n| `Create table table_name( col1 data_type UNIQUE,col2 data_type,col3 data_type);` | UNIQUE constraint ensures that all values in the column are different |\n| `Create table table_name( col1 data_type CHECK (condition),col2 data_type,col3 data_type);` | CHECK constraint ensures that all values in a column satisfy certain conditions |\n| `Create table table_name( col1 data_type Primary Key,col2 data_type,col3 data_type);` | Primary key is used to uniquely identify each row in a table |\n| `CREATE TABLE Orders (OrderID int NOT NULL, OrderNumber int NOT NULL,PersonID int, PRIMARY KEY (OrderID), FOREIGN KEY (PersonID) REFERENCES Persons(PersonID));` | Foreign key is used to link data from another table |\n\nDownload the Pdf for the Cheatsheet\n[Click Here👇](https://nehalkhan.gumroad.com/l/ccwau?layout=profile)\n\n### Note - `If face any issue regarding commands, please raise a issue i will solve for the same`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohdnehalkhan%2Fmysql-commands","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohdnehalkhan%2Fmysql-commands","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohdnehalkhan%2Fmysql-commands/lists"}