免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1215 | 回复: 0
打印 上一主题 下一主题

[服务应用] 在linux系统的数据库的简单学习 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-07-16 19:51 |只看该作者 |倒序浏览
linux数据库的练习
create table staff(
id int not null auto_increment,
name varchar(30) not null,
depart varchar(30) not null,
post varchar(20),
primary key(id)
)engine=innoDB charset=utf8;
insert into staff(id,name,depart,post) values(1,'zhang','教学部','讲师');
create table pers_info(
id int not null,
age int,
tel int,
email varchar(30),
wage int,
foreign key(id) references staff(id)
)engine=innoDB charset=utf8;
insert into pers_info(id,age,tel,email,wage) values(1,20,62760823,'zhang@sxkj.com',3000);
select * from pers_info order by age desc,wage desc;
insert into pers_info(id,age,tel,email,wage) values(2,23,62760303,'yang@sina.com',2890);
insert into pers_info(id,age,tel,email,wage) values(4,null,62760998,'xiejinghui@sina.com',3100);
create database sxkjtest;
create table t1(
id int not null,
name char(40),
city char(40),country char(40),
email char(40),
primary key(id))engine=innoDB charset=utf8;


create table t2(
id int not null,
name char(40) not null,
age int null,
tel int null)engine=innoDB charset=utf8;
create table t3(
id int not null,
name char(30) not null,
tel int,
addr char(40) not null,
primary key(id))engine=innoDB charset=utf8;
create table t5(
id int not null primary key auto_increment,
name char(40) not null
)engine=innoDB charset=utf8;
create table t4(
id int not null,
addr char(40) null,
foreign key(id) references t1(id))engine=innoDB charset=utf8;用foreign key 指定id列为外键,关键字references 决定来该列外键的值引用自表t1的主键id列。表t4的id列的所有取值必须是在表t1的id列中出现的值。
show create table t4;
alter table t4 engine=innoDB;
alter table t4 charset=utf8;
alter table t5 rename t6; 将表名T5改为表T6.
alter table t5 add (city char(40) not null); 使用alter table 在定义完成之后对表进行添加或删除列一些。
alter table t5 drop city;使用 alter table 修改表时,关键字 drop 表示删除之前添加的列。
modify 更新
alter table t4 modify addr char(50) not null default 'changsha';
修改表t4中的addr列数据类型为长度为50的字符类型,并且不为null,默认值为'changsha'.
alter table 修改表时,使用change关键字可以对列进行重命令。
alter table t4 change addr address char(40) not null default 'changsha';
drop table t5;
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bs                 |
| ds                 |
| mysql              |
| sxkjtest           |
| test               |
+--------------------+
drop database ds;
insert into t1(id,name,city,country,email) values(2,'yangbei','hainan','china','yangbei@qq.com'),(3,'wangguanwen','hainan','china','wangguanwen@sina.com');使用inser into语句一次插入多条数据时,每行数据放在一对圆括号内,多行数据之间使用逗号分隔。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP