How to create a table in MySQL database?

青灯夜游
Release: 2022-05-27 15:36:22
Original
22775 people have browsed it

How to create a table in MySQL database?

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

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

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

For example:

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

2), view the created table structure

The syntax format is:

show columns from [表名];
Copy after login

For example:

show colums from tb3;
Copy after login

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

For example:

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

2), query record

Grammar format:

select {filed1,filed2,...} from {表名};
Copy after login

Examples are as follows:

select id,username from tb3;
Copy after login

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!

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
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!