-
Using INSERT
Using DELETE
Using UPDATE
Uploading data with LOAD DATA INFILE
Extensions: REPLACE and TRUNCATE
(一)INSERT
insert into department values
(42, 'Finance'),
(128, 'Research and Development'),
(NULL, 'Human Resources'),
(NULL, 'Marketing');
DESC department departmentID int not null auto_increment primary key
所以后边两项 129,130.
我们来看看insert 这条语句的范式:
INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
[INTO] tbl_name [(col_name,...)]
VALUES ((expression | DEFAULT),...),(...),...
[ ON DUPLICATE KEY UPDATE col_name=expression, ... ]
LOW_PRIORITY/DELAYED: 这两个选项意在指示,你不能插入直到没有用户读此表,两者的区别:LOW_PRIORITY插入数据的时候lock 这张表了,而DELAYED 没有,你还可以读取。
IGNORE : 就是在批量进行插入的时候,可能你会对原数据产生crash,原数据UNIQUE,PRIMARY KEY等等重复出现,那么就会终止abort(当然指的是出现crash 的插入语句以后的所有语句就不能执行),现在加上ignore,就可以顺利执行完毕,不符合的插入语句不执行。
The REPLACE statement is exactly like the INSERT statement except that if a key clash occurs, the new row you are inserting will replace the old row.
(二)DELETE
delete from department where name='Asset Management'; 满足什么条件的行被从什么表中删除。
TRUNCATE TABLE employee; truncate 是给一张表情况== delete from table_name . 区别就是:它别delete 还有快,因为它的作用原理: drop table ,create table with no data.
(三)UPDATE
update employee set job='DBA' where employeeID='6651';
Name,Job,DepartmentID
Julia Lenin,Programmer,128
Douglas Smith,Programmer,128
Tim O'Leary,Programmer,128
(四)插入元数据从一个文件中(实际上有点类似于数据导入)
load data infile 'e:\\new_programmers.csv'
into table employee
fields terminated by ','
lines terminated by '\n'
ignore 2 lines
(name, job, departmentID);
load some data from a file:
1. windows 所以你要写入e:\\
2. field terminated by ','
3. line terminated by '\n'
4. 原资料的前两行是没用的数据 ignore 2 lines
5. 元数据中时有employeeID 字段,而我们给的数据对应插入的字段为(name,job,departmentID)