3.mysql的中文问题,database级操作,表级操作,数据CRUD,分组操作,时间和日期,字符串相关函数,表的约束(三)

2014-11-24 10:35:51 · 作者: · 浏览: 2
-----------+-------------+

selectdate_add(now(), INTERVAL 2 year) from dual;//增加两年

selectcharset('name') employee;

selectdate_add(now(), INTERVAL -1 day) 昨天, now() 今天, date_add(now(), INTERVAL +1 day) 明天;

9 字符串相关函数

selectconcat( charset('name'), 'aaaa') 自定义 from dual;

10 表的约束  

*定义主键约束 primarykey:不允许为空,不允许重复

*定义主键自动增长 auto_increment

*定义唯一约束 unique

*定义非空约束 notnull

*定义外键约束 constraintordersid_FK foreign key(ordersid) references orders(id)

*删除主键:altertable tablename drop primary key ;

createtable myclass

(

idINT(11) primary key auto_increment,

namevarchar(20) unique

);

createtable student(

idINT(11) primary key auto_increment,

namevarchar(20) unique,

passwdvarchar(15) not null,

classidINT(11), #注意这个地方不要少逗号

constraintstu_classid_FK foreign key(classid)references myclass(id)

);