数据库课堂笔记
来源:互联网 发布:数据库实用教程答案 编辑:程序博客网 时间:2024/05/19 17:07
第一章节
(1)用SQL语言创建数据库、建表。建表时为各表建立关键字、设置外码,数据暂不录入.
建库:
```create database school;
建表:
create table students(sid char(10) primary key,sname char(30) not null,email char(30),grade int);create table teachers(tid char(10) primary key,tname char(30) not null,email char(30),salary int);
create table courses(cid char(10) primary key,cname char(30) not null,hour int);
设置外码:
create table choices(no int primary key,sid char(10) not null,tid char(10),cid char(10) not null,score int,constraint fksid foreign key (sid) references students(sid),constraint fktid foreign key (tid) references teachers(tid),constraint fkcid foreign key (cid) references courses(cid),);
2) 为students表、courses建立按主键増序排列的索引
create index stusid on students(sid asc);
create index coucid on courses(cid asc);
3) 删除course上的索引
drop index courses.coucid;
students表中增加一个“出生日期”字段,类型为日期时间型
alter table studentsadd “出生日期” datetime;
5) 删除students中的“出生日期”字段
alter table studentsdrop column “出生日期”;
6) 删除SCHOOL数据库中的students表
alter table choicesdrop constraint fksid;drop table students;
摘要
- create database<数据库名>
功能:创建数据库 - create table <表名>
( <列名><数据类型> [列级完整性约束条件]
[,<列名><数据类型> [列级完整性约束条件]]
[,<列级完整性约束条件>] );
功能:创建一张新的表 - create [unique] index <索引名> on<表名>(<列名>);
功能:创建表的索引 - drop index 表名.索引名
功能:取消表的索引 - alter table <表名>add <列名><数据类型>;
alter table<表名> drop column<列名>;
功能:表中新增列及列数据类型和删除列 - drop table<表名>cascade;
功能:删除数据库中的表 - drop database <数据库名>
功能:删除数据库
0 0
- 数据库课堂笔记
- 数据库课堂笔记
- 数据库课堂笔记
- 数据库课堂笔记
- 数据库课堂笔记
- 数据库创建--创建表(课堂笔记)
- 数据库开发技术 课堂笔记1
- 数据库开发技术 课堂笔记2
- 数据库开发技术 课堂笔记3
- 数据库开发技术 课堂笔记4
- 数据库开发技术 课堂笔记5
- 数据库开发技术 课堂笔记7
- 课堂笔记
- 课堂笔记
- 课堂笔记
- 课堂笔记
- 课堂笔记
- 课堂笔记
- Uva 673 括号匹配
- easyui 动态添加列
- 【bzoj4064】[Cerc2012]The Dragon and the knights
- CS架构
- c++中的const
- 数据库课堂笔记
- ZOJ-3162-To Go or Not to Go
- H.264官方软件JM源代码简单分析-编码器lencod
- LightOJ 1047 - Neighbor House (dp)
- VS 2015 使用经验
- 第十一周项目1 - 二叉树算法验证(3)中序线索化二叉树的算法验证
- hdu 1247 Hat’s Words
- ping命令使用及返回总结
- 牛客网 | 链表中环的入口结点