06 2021 档案

摘要:1. 建表时设置1个主键 CREATE TABLE `Student`( `s_id` VARCHAR(20) primary key, `s_name` VARCHAR(20) , `s_birth` VARCHAR(20) , `s_sex` VARCHAR(10) )engine = Inno 阅读全文
posted @ 2021-06-26 23:45 Avicii_2018
摘要:创建用户: CREATE USER 'username'@'host' IDENTIFIED BY 'password'; username:账号名 host:指定该账号在哪台主机上登录,可以限制到指定机器ip。本地用户用localhost。如果任意主机登录则用通配符% password:密码,可以 阅读全文
posted @ 2021-06-26 18:01 Avicii_2018
摘要:增加列: alter table tablename add 列名 数据类型 comment '注释'; 增加列并指定位置在某个字段X后面: alter table tablename add 列名 数据类型 comment '注释' after X ; 增加列并指定位置在第一列 alter tab 阅读全文
posted @ 2021-06-26 17:53 Avicii_2018
摘要:desc 表名; 或者 describe 表名; 或者 show columns from 表名; 示例 : 阅读全文
posted @ 2021-06-26 17:35 Avicii_2018
摘要:1. where 与 having 的区别: where子句中不能使用分组函数 having子句中可以使用分组函数 where的执行顺序在having之前,因为where子句在 group by 子句之前,having 子句在 group by 之后 2. where 与 having 都可以用于对 阅读全文
posted @ 2021-06-26 17:02 Avicii_2018
摘要:使用聚合函数时,只返回一个结果, 所以要查询其他信息时,需要配合group by 函数使用 如下语句name会返回多个name中的一个,这显然是不行的 : select name,count(*) from student_info ; group by 的作用,就是对数据进行分组. group b 阅读全文
posted @ 2021-06-26 17:01 Avicii_2018
摘要:查看某张表的建表语句: (1) show create table emp_info ; (2) 在连接工具中,可以选中表右键 对象信息 DDL中即可看到建表语句 阅读全文
posted @ 2021-06-22 23:42 Avicii_2018
摘要:1 . 查看数据库实例下的表名 show tables; 阅读全文
posted @ 2021-06-22 23:40 Avicii_2018
摘要:drop table if exists student_info; create table student_info( sno varchar(10) primary key , sname varchar(10), sage int(3), ssex char(1), school varch 阅读全文
posted @ 2021-06-22 23:16 Avicii_2018
摘要:1. 给表起别名: select * from student_info a where a.sno = '001'; 或者 select * from student_info as a where a.sno = '002'; 2.给字段起别名: select name,school sc,ad 阅读全文
posted @ 2021-06-21 23:06 Avicii_2018
摘要:模糊查询: SELECT 字段 FROM 表 WHERE 某字段 Like 条件; ①% :表示任意0个或多个字符。可匹配任意类型和长度的字符,有些情况下若是中文,请使用两个百分号(%%)表示。 如下查询 将会把u_name为“张三”,“张猫三”、“三脚猫”,“唐三藏”等等有“三”的记录全找出来。 阅读全文
posted @ 2021-06-21 23:00 Avicii_2018
摘要:修改表名: ALTER TABLE TABLENAME RENAME TO NEWNAME; > TABLENAME 原表名, NEWNAME 新表名 或者 ALTER TABLE TABLENAME RENAME NEWNAME; > TABLENAME 原表名, NEWNAME 新表名 阅读全文
posted @ 2021-06-21 22:39 Avicii_2018
摘要:1. 增加主键 alter table 表名 add primary key(列名); 2. 删除主键 alter table 表名 drop primary key; 3.删除自增主键并新增主键 alter table student_info modify id int(3); -- 先删除该字 阅读全文
posted @ 2021-06-21 22:12 Avicii_2018