MySQL
When Codd started thinking about the relational model in 1969, he emphasized that a database (not related to a name) is not actually a collection of data, but a collection of facts (that is, true propositions).
("Database in Depth: Relational Theory for Practitioners, O'Reilly Media, 2005)
1. DDL(data definition language)
1. Build a table
DROP TABLE IF EXISTS T_DEMO;
CREATE TABLE t_demo(
uid int(10) PRIMARY key auto_increment,
uname VARCHAR(10)
);
2. Modify the table name
ALTER TABLE t_demo rename to t_demo01;
ALTER TABLE t_demo01 rename to t_demo;
3. Modify the table structure
-- 1、添加一列
ALTER TABLE t_demo ADD(sex VARCHAR(10));
-- 2、删除一列
ALTER TABLE t_demo DROP COLUMN sex;
-- 3、修改列类型
ALTER TABLE t_demo MODIFY uname INT(10);
ALTER TABLE t_demo MODIFY uname VARCHAR(10);
-- 4、修改列名及列类型
ALTER TABLE t_demo CHANGE COLUMN uname uuname VARCHAR(10); -- mysql用法
2. DML (data manipulation language)
1. Add records
INSERT INTO t_demo VALUES(11,'pku'),(12,'THU'),(13,'ustc');
2. Modify the record
UPDATE t_demo SET uuname ='newUstc' WHERE uuname='ustc';
UPDATE t_demo SET uuname ='ustc' WHERE uid=13;
3. Delete records
Delete method | Behavioral characteristics of this approach |
---|---|
DELETE FROM t_demo; | Delete all records in the table |
DROP TABLE t_demo; | Delete table structure |
TRUNCATE TABLE t_demo; | 1. First delete the table and create the table again. The effect is equivalent to deleting all records in the table. 2. In the case of a large amount of data, especially in the case of an index in the table, the operation efficiency is high. 3. Indexes can provide query efficiency, but will affect the efficiency of additions, deletions, and modifications. |
3. DCL (Data Control Language)
to be added...