本随笔你将看到:
一.对于数据库表中数据的增删改查
二.数据库中常用函数(聚合函数,日期函数,字符串函数,数字函数)
一.对于数据库表中数据的增删改查
mysql中对于表的操作:
1.创建表:
create table '表名'(
'列名' 数据类型 字段属性索引约束注释 ;
)
2.修改表:
修改表名:alter table '旧表名' rename '新表名';
在原表中添加某一列:alter table '表名' add ‘列名’ 数据类型 是否为空等属性;
修改列名: alter table ‘表名’ change ‘原列名’ `新列名` 数据类型 属性;
删除列名:alter table ‘列名’ drop ‘列名’;
添加主键:
alter table 表名 add constraint 主键名
primary key 表名(主键字段);
注意:主键名要写成pk_主键字段(列名),主键字段就是被设置为主键的列名
添加外键:
alter table 表名 add consteraint 外键名
foreign key (外键字段)
references 主键名(主键列名);
注意:外键名要设为fk_外键名_主键名 如:fk_student_sex
增