CH 2
CH 2
Introduction to MYSQL
1. Introduction To MYSQL
MySQL is an open source RDBMS that uses SQL to create and manage databases. As a relational database, MySQL
stores data in tables of rows and columns organized into schemas. A schema defines how data is organized and
stored and describes the relationship among various tables.
2. Classification of MYSQL commands (DDL, DML)
MySQL commands are classified into three main types based on their purpose in the database:
Data Definition Language (DDL)
Used to define the database schema, including creating, modifying, and deleting database structures
Data Manipulation Language (DML)
Used to manipulate the data within the database, including creating, reading, updating, and deleting data
Data Control Language (DCL)
Used to control access to the database and implement security on database objects
Here are some examples of DDL and DML commands:
DDL
CREATE: Creates a new table, index, function, view, store procedure, or trigger
ALTER: Modifies an existing table, such as adding a new column or changing a data type
DROP: Permanently deletes an existing database, table, or trigger
TRUNCATE: Deletes all records from a table, including all spaces allocated for the records
RENAME: Renames an existing object in the database
DML
SELECT: Used to conduct data analysis or create new tables and views
INSERT: Used to create data
UPDATE: Used to update data
DELETE: Used to delete data
8. Modify structure?
To modify the structure of a table in SQL, you can use the ALTER TABLE command:
Add a column: Use the syntax ALTER TABLE table_name ADD column_name data_type. The new column is added
to the end of the existing columns.
Change a column: Use the CHANGE clause to rename a column or change its data type. For example, you can
change a column from STRING to TIMESTAMP.
Add or remove constraints: You can add or remove constraints on an existing table.
Declare a default value: You can declare a default value for a field.
Rename a table: You can rename the table itself.
Altering a table's structure can cause data loss or rounding errors. It can also break other parts of your application
that may refer to the changed field.
9. Show all tables created in a database