Page 68 - 2611_SmartGPT Pro V(5.0) C-8
P. 68
USING DATABASE
To work with a specific database, you must first select it using the
USE command. The syntax is as follows:
USE database_name;
DELETING DATABASE
If you no longer need a database, you can delete it. However, this action is permanent and
removes all tables and data within the database. Always ensure that you have a backup before
deleting a database.
The syntax to delete a database is:
DROP DATABASE database_name;
CREATING AND MANAGING TABLES
In MySQL, tables are the fundamental building blocks of a database for storing data in an
organised mannner. Table management involves creating, viewing, modifying and deleting these
structures as needed.
CREATING TABLES
A table, also known as a relation, organizes data into rows and columns. To create one, you use
the CREATE TABLE command. The syntax is as follows:
CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
.....
.....
column_nameN data_type(size)
);
While creating a table in SQL, it is necessary to give a
data type for each field/column.
Let’s create a table named Students having StudentID,
FirstName, LastName, Age and Grade fields in the School database.
You can create more tables in the database in a similar way.
SHOWING TABLES
To view the list of tables in a database, use the SHOW TABLES command. The syntax is as follows:
SHOW TABLES;
66 Computer Science (V5.0)-VIII

