Home > Database > Mysql Tutorial > body text

Addition, deletion and modification of mysql table

黄舟
Release: 2017-01-16 13:19:07
Original
1143 people have browsed it

Create a class table

create table class(
id int primary key auto_increment,
sname varchar(10) not null default '',
gender char(1) not null default '',
company varchar(20) not null default '',
salary decimal(6,2) not null default 0.00,
fanbu smallint not null default 0
)engine myisam charset utf8;
Copy after login

View the structure of a table desc [table name]

Add data to the table---select a table--> Add which columns of data-->What values ​​to add respectively

Insert all columns

insert into class
(id,sname,gender,company,salary ,fanbu)
values
(1,'张三','男','百度',8888.88,234);
Copy after login

or

insert into class
values
(1,'张三','男','百度',8888.88,234);
Copy after login

Insert only part of the column content

insert into class
(sname,gender,salary)
values
('刀锋','男',9000.00);
Copy after login

There is no id data inserted in the above example, but the id is auto-incrementing

Add multiple pieces of data at one time

insert into class
(sname,company,salary)
values
('刘备','皇室成员',15.28),
('曹操','宦官后代',88.45),
('孙策','江东集团',188.25);
Copy after login

update Modify the data in a table
Elements are
Change that table: class
Change those columns: gender, company, fanbu, etc.
What value should I change to:'Female','Qiandu'
Specify which one It takes effect locally: For example, id=2 (must add filter conditions)

update class
set fanbu=123
where id=2
update class
set fanbu=453,gender='男'
where sname='孙策';
Copy after login

#Delete---Note: Deletion refers to deleting the entire row, and there is no deletion of a certain item in a flight. Several columns
#Delete elements
#Delete the data in that table: class
#Delete which row of data

Delete salary>8889 person

delete from class
where salary>8889;
Copy after login

Delete the data of the entire table

delete from class;
Copy after login

The above is the addition, deletion and modification of the mysql table. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


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