This article mainly introduces the common operations of Mysql DDL. The article introduces it in great detail through sample code, which has certain reference learning value for everyone's study or work! Let’s learn from the editor below.
SQL statements can be mainly divided into the following three categories:
DDL statements: Data definition language, these statements define different data segments, databases, tables, columns, indexes and other database objects. Commonly used statement keywords mainly include create
, drop
, alter
, etc.
DML statement: Data manipulation statement, used to add, delete, update and query database records, and check data integrity. Commonly used statement keywords mainly include insert
, delete
, update
, select
, etc.
DCL statement: Data control statement, a statement used to control the direct permission and access levels of different data segments. These statements define the database, tables, fields, user access rights and security levels. The main statement keywords include grant
, revoke
, etc.
What we mainly introduce today is the DDL statement
1. Create a database
Syntax:
create database 数据库名;
Select the database to operate : USE database; For the database to be operated, we need to use use to select it!
View all data tables in the database show tables;
mysql> create database test;//创建数据库 Query OK, 1 row affected (0.00 sec) mysql> use test;//使用刚创的数据库 Database changed mysql> show table; Empty set (0.11 sec)//查看数据库中的表,因为我们没有创,所以为空
2. Delete the database:
Syntax:
drop database 数据库名;
Example:
mysql> drop database test;//删除我们刚刚创建的数据库
3. Create a table (in which database to create the table, you need to use use to select the database to be operated first)
Syntax:
create table 表名( 字段1名 字段1类型 列的约束条件, 字段2名 字段2类型 列的约束条件, ...);
Example:
mysql> create table student//创建数据表 ->( ->ID Int, ->Name varchar(12) ); Query OK, 0 row affected (0.13 sec)
4. Delete table
Syntax:
drop table 表名;
Example:
mysql> drop table student;//删除我们刚刚创建的数据表
Recommended tutorial: mysql video tutorial
The above is the detailed content of Take you to understand mysql DDL in one minute. For more information, please follow other related articles on the PHP Chinese website!