ITPub博客

首页 > 数据库 > MySQL > MySQl学习笔记(一)

MySQl学习笔记(一)

MySQL 作者:lq071307 时间:2014-01-09 22:34:44 0 删除 编辑
2014/1/8
今天尝试用DOS方式执行了许多MySQL的命令,顿然命令行的操作速度比GUI方式大很多,学到了不少东西,总结关键的几点如下;
1.建议含有外键约束的两张表worker,department.

create table department(d_id int(4) primary key auto_increment,
d_name varchar(10)
);

create table worker(id int(4) primary key auto_increment,
name varchar(20) not null,
d_id int(4) not null,
constraint worker_fk foreign key(d_id)
references department(d_id)
);

个人理解:worker表里除了自己的主键外还有一个外键,它定义于department,故称d_id是department的主键,是worker的外键。

定义约束的语法:constraint 约束名 foreign key(字段名) references 其他表(字段名)

2.显示一张表的结构有两种方法 describe table或者 show columns from table,其中第二种方法执行速度更快
3.修改字段birthday到sex字段前的语法为:alter table teacher modify birthday datetime after name(name开始是在sex之前)
这里注意birthday 的数据类型 datetime不能缺少!!

4.查询一类事物所属的类型的种类,比如所有记录都有type字段:可以用 select distinct type from table;
5.table1.name = table2.name 此处的等号就是传说的等值连接;
<!-- 正文结束 -->

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22138073/viewspace-1114682/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2009-07-18