表头:
查看当前数据库:SELECT DATABASE();
创建数据表:CREATE TABLE [IF NOT EXISTS] table_name (
colum_name(列名称) data_type(数据类型),
...
)#IF NOT EXISTS的作用是创建某个表时,存在这个表的话不会提示错误
例:CREATE TABLE tb1(
username VARCHAR(20),
age TINYINT UNSIGNED NOT NILL, #加'NOT NULL'后表示禁止为空
salary FLOAT(8,2) UNSIGNED
);
查看当前数据库的表:SHOW TABLES;
查看mysql数据库的表:SHOW TABLES FROM mysql;
查看数据表的结构:SHOW COLUMNS FROM tbl_name;
数据表中写入数据:INSERT [INTO] tbl_name [(col_name,...)] VALUES(val,...)
例:1.INSERT tb1 VALUES('Tom',25,7863.25);
2.INSERT tb1(username,salary) VALUES('John',4500.69);#只写入usernam,esalary的 值
记录查找:SELECT expr,... FROM tbl_name
例:SELECT * FROM tb1;
去重复:SELECT * FROM teacher GROUP BY depart
SELECT iid,iname FROM teacher GROUP BY isex