一:向表格中插入数据,查询数据
向表格中插入 一条记录:INSERT INTO tablename VALUES (值1,值2,、、、)
或INSERT INTO tablename(列1,列2、、、) VAlues(值1,值2、、、);
从表格中查询记录:SELECT * FROM tablename; #查询表中所有数据
或SELECT 列名称1,列名称2、、、 FROM tablename; #查询表中指定数据
mysql> INSERT INTO course VALUES(1,‘linux‘,45,‘basic‘); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO course(idid,course_length) VALUES(2,40) -> ; Query OK, 1 row affected (0.00 sec) mysql> SELECT * FROM course -> ; +------+-------------+---------------+----------+ | idid | course_name | course_length | category | +------+-------------+---------------+----------+ | 1 | linux | 45 | basic | | 2 | NULL | 40 | NULL | +------+-------------+---------------+----------+ 2 rows in set (0.00 sec) mysql> SELECT idid,course_name,course_length -> ; ERROR 1054 (42S22): Unknown column ‘idid‘ in ‘field list‘ mysql> SELECT idid,course_name, course_length FROM course; +------+-------------+---------------+ | idid | course_name | course_length | +------+-------------+---------------+ | 1 | linux | 45 | | 2 | NULL | 40 | +------+-------------+---------------+ 2 rows in set (0.00 sec) mysql>
按条件查询数据:
从表格中按条件查询一条记录:SELECT 列名称 FROM 表名
时间: 2024-10-03 05:33:36