时间:2021-07-01 10:21:17 帮助过:2人阅读
基本语句:
SELECT语句(从表或试图获取数据)
查询employees表里的所有信息
1 SELECT * FROM employees;
只查看员工的名字,姓氏和职位,请使用以下查询:
1 SELECT lastname, firstname, jobtitle FROM employees;
where语句(根据指定的过滤表达式或条件来指定要选择的行)
假设只想从employees
表中获取销售代表员工,可使用以下查询
SELECT lastname, firstname, jobtitle FROM employees WHERE jobtitle = ‘Sales Rep‘;
数据的增删改查:
首先创建一个表:
USE testdb; CREATE TABLE IF NOT EXISTS tasks ( task_id INT(11) AUTO_INCREMENT, subject VARCHAR(45) DEFAULT NULL, start_date DATE DEFAULT NULL, end_date DATE DEFAULT NULL, description VARCHAR(200) DEFAULT NULL, PRIMARY KEY (task_id) )ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO(插入数据)
1 INSERT INTO table(column1,column2...) 2 VALUES (value1,value2,...);
多行:
INSERT INTO table(column1,column2...) VALUES (value1,value2,...), (value1,value2,...), ...;
如果为表中的所有列指定相应列的值,则可以忽略INSERT
语句中的列列表,如下所示:
INSERT INTO table VALUES (value1,value2,...), (value1,value2,...), ...;
update语句(更新数据)
UPDATE table_name SET column_name1 = expr1, column_name2 = expr2, ... WHERE condition;
eg:
UPDATE employees SET email = ‘mary.new@yiibai.com‘ WHERE employeeNumber = 1056;
多行:
UPDATE employees SET lastname = ‘Hill‘, email = ‘mary.hill@yiibai.com‘ WHERE employeeNumber = 1056;
delete语句(删除数据)
DELETE FROM table_name WHERE condition;
MySQL 入坑
标签:pre rip tar select font article table where 数据