Home  >  Article  >  Database  >  How to create a table in mysql

How to create a table in mysql

藏色散人
藏色散人Original
2019-06-01 11:21:1019864browse

How to create a table in mysql

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

use t1;  //t1是数据库名

As shown in the figure:

How to create a table in mysql

2. Create a database table in this database

2.1 First establish the table structure (which can be understood as the column name of the table, that is, the field name). In the actual production process, the table structure is required Carefully designed.

The common syntax format is:

1 CREATE TABLE table_name (column_name column_type);

For example:

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

2.2 View the created table structure

The syntax format is:

1 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.

3.1 Record insertion

The syntax format of record insertion:

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

For example:

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

##3.2 Query records

Syntax format:

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

For example:

select id,username from tb3;

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