数据库的学习-主表操作
来源:互联网 发布:java抽象方法的作用 编辑:程序博客网 时间:2024/06/03 22:40
--datafile '[数据文件的路径]'
--size nM 大小
--autoextend on next nM 满了后选着扩充的大小
创建用户 web 密码123456 对应表空间web
create user web identfied by 123456 default tablespace web
赋予 web数据管理员权限 该用户可以操作数据库
grant dba to web
--数字
number --代表整型和浮点型
number(p,s) p代表整体长度,s代表小数的精度
number(5,2) 整数部分为3,小数部分为2
int 实际上是number的子集
number(10,0) 这样就代表的是一个整数
--字符
--定长字符
char
char(10) 代表创建一个定长字符,最多只能存放10个字符,如果不到10个,那么整个定长字符所占空间还是10个
--非定长字符
--unicode非定长字符
nvarchar
nvarchar2
--非unicode非定长字符
varchar
varchar2
--日期
date 2017-08-10
datetime 2017-08-10 09:41:13
Timestamp 时间戳 20170810094113
text 大文本
clob char large object
blob binary
create table student 表格式
(
stu_id int,
stu_name varchar(20),
stu_age number(3,0),
stu_gender char(2),
stu_birthday date,
clazz_id int
)
--添加主键
alter table student add constraint pk_stu_id primary key(stu_id)
索引 聚集索引
insert into student(stu_id,stu_name,stu_age,stu_gender,stu_birthday,clazz_id)
values(1,'云妹',22,'男',to_date('1995-08-10','yyyy-MM-dd'),1)
drop table student 删除表
添加表clazz 和其内容
create table clazz
(
clazz_id int,
clazz_name varchar(20)
)
alter table clazz add constraint pk_clazz_id primary key(clazz_id)
insert into clazz(clazz_id,clazz_name) values(1,'J0626')
--外键约束
alter table student add constraint fk_clazz_id foreign key(clazz_id) references clazz(clazz_id)
--级联置空
alter table student add constraint fk_clazz_id foreign key(clazz_id) references clazz(clazz_id) on delete set null
--级联删除
alter table student add constraint fk_clazz_id foreign key(clazz_id) references clazz(clazz_id) on delete cascade
delete from student where stu_id=2
--oracle 从删库到跑路
truncate --彻底删除
delete from clazz where clazz_id=1 单项删除
--check约束 不能添加与约束违背的内容
alter table student add constraint ck_stu_gender check (stu_gender in('男','女'))
alter table student add constraint ck_stu_age check (stu_age <120)
--unique约束 唯一
alter table student add constraint uk_stu_name unique(stu_name)
--非空约束 not null
alter table student modify stu_birthday constraint nt_stu_birthday not null
--修改表名
rename students to student
--删除约束
--删除非空约束
alter table student drop constraint nt_stu_birthday
--删除unique约束
alter table student drop constraint uk_stu_name
--删除check约束
alter table student drop constraint ck_stu_gender
--删除主键约束
alter table student drop constraint pk_stu_id
- 数据库的学习-主表操作
- Mysql学习点滴记录(1)--》数据库和表的操作
- ThinkPHP学习笔记(十八)数据库表的关联操作
- Oracle数据库学习之数据类型和表的操作
- 数据库学习第一篇(对基本表的操作)
- 数据库学习第二篇(对基本表数据的操作)
- MySQL学习01_数据库及表的操作
- MySQL学习(数据库和表的基本操作)
- MySQL学习笔记一(数据库及表的操作)
- MySQL学习(数据库和表的基本操作)
- 数据库表的操作
- 数据库表的操作
- 数据库 表的操作
- 数据库表的操作
- 学习二:MySql数据库的基本操作
- MySQL 学习<二> 数据库的基本操作
- 学习Linux操作数据库的命令
- vc++数据库操作的学习笔记
- java线程和线程组的初始化
- 未能从程序集“Oracle.ManagedDataAccess”加载 “OracleInternal.Common.ConfigBaseClass”
- 2726:集合问题(3.7数据结构之堆)
- HDU 6097 数学几何
- 基础排序算法个人小结(未完待续).md
- 数据库的学习-主表操作
- 分页规范
- Aggressive cows (二分)
- Java类和对象的概念
- mysql查询今天,昨天等方法
- Water 4.0: The Past, Present, and Future of the World's Most Vital Resource
- XAMPP中apache出现错误 Error: Apache shutdown unexpectedly.
- 项目管理杂谈
- python资源下载与各种库的安装