Home  >  Article  >  Database  >  Addition, deletion and modification of mysql table

Addition, deletion and modification of mysql table

黄舟
黄舟Original
2017-01-16 13:19:071132browse

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;

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);

or

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

Insert only part of the column content

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

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);

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='孙策';

#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;

Delete the data of the entire table

delete from class;

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


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
Previous article:mysql column typeNext article:mysql column type