Home  >  Article  >  Database  >  Take you to understand mysql DDL in one minute

Take you to understand mysql DDL in one minute

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-03-23 17:51:392520browse

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.

Take you to understand mysql DDL in one minute

SQL classification:

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Why use MySQL indexes?Next article:Why use MySQL indexes?