Home  >  Article  >  Database  >  How to create a table in MySQL database?

How to create a table in MySQL database?

青灯夜游
青灯夜游Original
2019-05-20 14:10:2022870browse

How to create a table in MySQL database?

1. After successful login, first enter a certain database (not the database server)

use t1;  //t1是数据库名

As shown in the picture:

How to create a table in MySQL database?

2. Create a database table in this database

1), first create the table structure (can be understood as the column name of the table, also It is the field name) In the actual production process, the table structure needs to be carefully designed.

The common syntax format is:

CREATE TABLE table_name (column_name column_type);

For example:

create table tb3(
    id smallint unsigned auto_increment primary key,
    username varchar(20) not null4
    );

2), view the created table structure

The syntax format is:

show columns from [表名];

For example:

show colums from tb3;

You can see that the table structure in table t3 contains two fields: id ,username;

The values ​​of both fields are not allowed to be empty, and the id field is the primary key.

3. Record insertion and search

The table records in the database correspond to the rows in the table.

1), record insertion

The syntax format of record insertion:

inset {表名} (filed1,field2,....) values (value1,value2,....);

For example:

insert tb3 (id,username) values (4,'jona');

2), query record

Grammar format:

select {filed1,filed2,...} from {表名};

Examples are as follows:

select id,username from tb3;

The above is the detailed content of How to create a table in MySQL database?. 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