Database CLI: Difference between revisions

From acumen Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 7: Line 7:
#<code>>SELECT * FROM <name of table>;</code> Prints all records from the named table, eg: <code>SELECT * FROM tbl_entity;</code>
#<code>>SELECT * FROM <name of table>;</code> Prints all records from the named table, eg: <code>SELECT * FROM tbl_entity;</code>
#<code>>SELECT * FROM <name of table> WHERE <condition>;</code> Prints all records from the named table where the condition is met, eg: <code>SELECT * FROM tbl_entity WHERE td LIKE "CE";</code>
#<code>>SELECT * FROM <name of table> WHERE <condition>;</code> Prints all records from the named table where the condition is met, eg: <code>SELECT * FROM tbl_entity WHERE td LIKE "CE";</code>
#<code>>SELECT <columns> FROM <name of table> WHERE <condition>;</code> Prints named columns from the named table where the condition is met, eg. <code>SELECT td, berth FROM approach_berth WHERE dockers = "Crewe_Station";</code>
#<code>>SELECT COUNT(*) FROM <name of table>;</code> Prints a count of table records for the named table.
#<code>>SELECT COUNT(*) FROM <name of table> WHERE <condition>;</code> Prints a count of table records for the named table where the condition is met, eg. <code>SELECT COUNT(*) FROM users WHERE email LIKE "%networkrail.co.uk%";</code>

Latest revision as of 17:33, 7 July 2020

This page contains some helpful commands to use at the MariaDB CLI.

  1. >SHOW DATABASES; List all databases;
  2. >USE <database>; Use a particular database, eg: >USE bplan;
  3. >SHOW TABLES; List all tables in a database (after using USE);
  4. >DESCRIBE <name of table>; Prints the structure of a table, eg: DESCRIBE tbl_entity;
  5. >SELECT * FROM <name of table>; Prints all records from the named table, eg: SELECT * FROM tbl_entity;
  6. >SELECT * FROM <name of table> WHERE <condition>; Prints all records from the named table where the condition is met, eg: SELECT * FROM tbl_entity WHERE td LIKE "CE";
  7. >SELECT <columns> FROM <name of table> WHERE <condition>; Prints named columns from the named table where the condition is met, eg. SELECT td, berth FROM approach_berth WHERE dockers = "Crewe_Station";
  8. >SELECT COUNT(*) FROM <name of table>; Prints a count of table records for the named table.
  9. >SELECT COUNT(*) FROM <name of table> WHERE <condition>; Prints a count of table records for the named table where the condition is met, eg. SELECT COUNT(*) FROM users WHERE email LIKE "%networkrail.co.uk%";