Deletions of change table records
1.MySQL of DML user to create data tables
create table user( id int unsigned not null auto_increment primary key, user_name varchar(20) not null, password char(32) not null, email varchar(50) not null, mobile char(11) not null, fee decimal(10,2) not null default 0.00, age tinyint(3) unsigned not null );
Check user data in the table:
select * from user;
The DML 2.MySQL insert several methods database
insert into table (column 1, column 2, ......) values (value column 1, column 2 value, ......); wherein the values of column and one correspondence;
法一:insert into user(user_name,password,email,mobile,fee,age) values('jack',md5('123456'),'[email protected]','13045678911',123.11,29); 法二:insert into user(user_name,email) values('jack','[email protected]');
法三:insert into user values(3,'jack2',md5('1234562'),'[email protected]','13045678900',13.01,25);
note:
(1) If the set sql_mode STRICT_TRANS_TABLE, two methods will be an error, since in this mode, if the value of a transaction can not be inserted into a table, the current operation is interrupted, without any restrictions on the non-transactional table, i.e. in this mode strict mode. Specifically to see: the MySQL provided the analytical sql_mode ; ERROR 1364 (HY000): Field, '***' A default value does Not have have Solution
(2) the latest version of MySql remove the password function ; MySQL database built-in encryption function summary
3. MySQL's DML insert garbled characters workarounds
4.MySQL of DML data update
update table values set lie1 = column 1, column 2 = 2 WHERE condition column value;
Note that without where conditions can modify all records
Before the amendment user table:
(1) execute the following command after the update:
update user set age=50 where id=2;
user table updated to:
(2) execute the following command after the update:
update user set fee=11.10 where fee=0.00;
user table updated to:
(3) execute the following command after the update:
update user set user_name='zhang' where user_name!='lidehua';
user table updated to:
(4) execute the following command after the update:
update user set email='[email protected]' where email='';
user table updated to:
(5) execute the following command after the update:
update user set user_name='wang' where id in(1,3);
user table updated to:
(6) execute the following command after the update:
update user set mobile='88888888888' where id between 2 and 3;
user table updated to:
(7)执行以下更新命令后:
update user set password=md5('456789'),mobile='13078945612',age=41 where id=3;
user表更新成:
5.MySQL之DML数据的删除
(1)delete from 表名 where 条件;注意:不加where会删除所有的记录
(2)truncate 表名;注:是DDL的
区别:
truncate将表清空了,插入数据时id会从头开始排;用delete删除整个表或者某一行数据,删除的id值仍被占用,插入数据时,id会紧接着删掉的id值进行递增;
truncate适用于删除垃圾数据;