Home > Database > Mysql Tutorial > body text

How to create a table in mysql

藏色散人
Release: 2019-06-01 11:21:55
Original
19868 people have browsed it

How to create a table in mysql

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

use t1;  //t1是数据库名
Copy after login

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);
Copy after login

For example:

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

2.2 View the created table structure

The syntax format is:

1 show columns from [表名];
Copy after login

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,....);
Copy after login

For example:

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

##3.2 Query records

Syntax format:

  {filed1,filed2,...}  {表名};
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!