orcle11gR2建表步骤及常用命令(navicat)

环境:Navicat Premium 15、 win10 1909
一、创建表空间
二、创建用户并授权
三、建表,插入数据
四、其他命令

创建表空间

-- 创建表空间并设置表空间名
CREATE tablespace "表空间名" 
-- 设置文件名 建议和表空间名保持一致
datafile 'xxx'['自定义路径\**\xxx.dbf  ']
-- 设置大小
SIZE 50 M 
-- 允许扩容,最大容量为1000M,每次增量为5M
autoextend on [next 5M maxsize 1000M];

创建用户

CREATE USER "新用户名" 
-- 设置密码
IDENTIFIED BY "密码" 
-- 设置默认表空间
DEFAULT TABLESPACE "表空间名" 
-- 设置临时表空间
TEMPORARY TABLESPACE "TEMP";
-- 设置角色权限
GRANT "CONNECT", "DBA", "RESOURCE" TO "新用户名";
ALTER USER "新用户名" DEFAULT ROLE "CONNECT", "DBA", "RESOURCE";
-- 设置服务器权限
GRANT CREATE VIEW TO "新用户名" WITH ADMIN OPTION;

创建user表,插入数据

-- 创建新用户
create table "user"(
	"id" NUMBER,
	"username" varchar2(30) not null,
	"password" varchar2(16) not null,
	primary key("id")
);

INSERT INTO "user" VALUES ('1', '张三', '123456');
...

其他命令

-- 新增列,当同时添加多个字段时,add后的括号不可省略,除非只有一个字段
alter table tableName add(columnName1 dataType1,columnName2 dataType2);

-- 修改列的数据类型
alter table tableName modify columnName dataType;

-- 修改列的字段名
alter table tableName rename column oldName to newName;

-- 删除字段,无论删除几个字段括号都不可省略
alter table tableName drop (columnName1,col2...,coln);

-- 删除用户
drop user "用户名" cascade;

-- 建立约束
alter table tableName1 add constraint 约束名 
primary key (columnName)foreign key (col1) references tableName2(col2)check(用户自定义完整性约束条件);

-- 添加not null约束必须使用modify,不能用add
alter table tableName modify columnName not null

-- 修改约束                 
alter table tableName modify columnName
primary keynot nullforeign key references tableName2(tableName2的主键);

-- 删除约束
alter table tableName drop
primary key | unique(col) | constraint constraint_name [cascade];                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
-- 删除表空间及其数据文件
DROP tablespace "表空间名" including contents AND datafiles cascade constraints;

分页 ,oracle无limit关键字,使用关键字rownum

查询前n条数据:
select * from book where rownum<=n	

查询第m条到第n条数据
前提:
1、大数在前,小数在后面
2、都是小于

select * from book where rownum<=m
minus
select * from book where rownum<n

A minus B将只去除A跟B的交集部分(A减B)
Oracle的minus是按列进行比较的,所以A能够minus B的前提条件是结果集A和结果集B需要有相同的列数,
且相同列索引的列具有相同的数据类型。
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值