Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The data table flow of operating Mysql

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following content mainly brings you the data table process of operating Mysql. The knowledge mentioned here is slightly different from books. It is summarized by professional technicians in the process of contacting users. It has certain experience sharing value and hopes to bring help to readers.

This article brings to you the content is about Mysql data table operation method introduction, there is a certain reference value, there is a need for friends can refer to, I hope to help you.

data table interpolation

The most important operation in the operation data table is to save our website data, user data. Let's look at the rules of command:

INSERT [INTO] tbl_name [(col_name,col_name,...)] VALUES(val,val,...)

From the rules above we can see that [(col_name,col_name,...)] Yes can be filled in or not, the difference is that; do not fill in [(col_name,col_name,...)] You must pass in all the field values at once, fill in [(col_name,col_name,...)] You can pass in the corresponding col_name value. (Recommended course: MySQL tutorial)

So, let's look at the data table that we built last time. The structure of user is passing values. Enter the command.

SHOW COLUMNS FROM user;

We can see that there are four fields usename,age,passwrod,gz, so let's interpolate all of them at once.

INSERT user VALUES('Tom',25,'abc123456',12000);

Run Command ~ Success.

Now let's interpolate between usename and passwrod.

INSERT user (usename,passwrod) VALUES('Jieke','101010');

Run Command ~ Success

Find Record Value

We have just inserted a few values, now let's query whether the values of the fields are the same as what we inserted.

Find Record Value Command Rules:

SELECT expr,... FROM tbl_name;

Enter command:

//Of course the actual query command is very, now just demonstrate the simple lookup command SELECT * FROM user;

You can see that the values you just inserted are already in the data table.

null and non-null

In the website registration information, there are required fields and fillable fields. This setting is also available in mysql, which is null and non-null NULL,NOT NULL. Now let's create a new data table and create fields.

CREATE TABLE newuser( name VARCHAR(20) NOT NULL, age TINYINT UNSIGNED NULL)

Above we set two fields, name field can not be null, age field can be null.

Now let's insert field values

INSERT newuser (name,age) VALUES('Timo',null);

Insert value successfully.

** Now, let's try inserting NULL in the name field.

INSERT newuser (name,age) VALUES(NULL,NULL);

Columns 'name' cannot be null. So the null and non-null values we set have been successfully validated.

default value

We can set default values for fields, which are automatically assigned when records are inserted if they are not explicitly assigned.

Now let's recreate a table tb2 and set defaults for sex in name,sex. Enter the command line:

CREATE TABLE tb2( name VARCHAR(20), sex ENUM('1','2','3') DEFAULT '3' );

insert record name, not insert record for sex

INSERT tb2(name) VALUES('ggb');

Insert successful, we record the output to the data table to see if sex has a value

You can see that the sex value is 3, which has been assigned the default value.

The above is Mysql data table operation method introduced in detail, more please pay attention to other related articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report