Before creating a table, ensure you have selected the appropriate database using the USE
statement.
Syntax:
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
...
);
Example:
-- Create a table named 'cats' with columns for name and age
CREATE TABLE cats (
name VARCHAR(100),
age INT
);
To list all tables in the currently selected database, use the SHOW TABLES
command.
Syntax:
SHOW TABLES;
Example:
-- Show all tables in the current database
SHOW TABLES;
To display the columns of a specific table, use the SHOW COLUMNS
command.
Syntax:
SHOW COLUMNS FROM table_name;