美文网首页
oracle常用基础命令

oracle常用基础命令

作者: AlicFeng | 来源:发表于2017-08-10 23:56 被阅读35次
  • 使用系统用户登录
[username/password][@server][as sysdba|sysoper]
  • 查看登录的用户
show user
  • 启用scott用户
alter user scott account unlock|lock;
  • 创建表空间
# 表空间
create tablespace $teblespace_name datafile '$filepath' size $sizeM;

# 临时表空间
create temporary tablespace $teblespace_name tempfile '$filepath' size $sizeM;
  • 查看表空间的路径
select file_name from dba_data_files where tablespace_name='$tablespace_name';

# 临时表空间的路径
select file_name from dba_data_files where tablespace_name='$tablespace_name';

  • 修改表空间
# 设置联机或脱机状态
alter tablespace $tablespace_name online | offline;

# 增加数据文件
alter tablespace $tablespace_name add datafile '$filepath' size $sizeM;
# 删除数据文件 注意不能删除第一个否则全部删掉
alter tablespace $tablespace_name drop datafile '$filepath' size $sizeM;
  • 删除表空间
# 仅仅删除表空间
drop tablespace $tablespace_name
# 删除表空间以及数据文件
drop tablespace $tablespace_name include contents

创建表

create table $table_name 
(
$column_name datatype,
...
)

create table userinfo
(
id number(6,0),
username vachar2(20),
regdate date
);
  • 修改表
# 添加字段
alter table $table_name add column_name datatype;

# 更改数据的类型
alter table $table_name modify column_name datatype;

# 删除字段
alter table $table_name drop column column_name;

# 修改字段名
alter table $table_name rename column $column_name to $new_column_name;

# 修改表名
rename $table_name to $new_table_name;
  • 删除表
# 删除表数据
truncate table $table_name

# 删除数据表
drop table $table_name

a

  • 插入数据
insert into (id,username,regdate) values (1,'alicfeng',sysdate);
  • 复制数据
# 建表时复制数据
create userinfo_new as select * from userinfo;
create userinfo_new as select id,username from userinfo;

# 在添加时复制 对用的字段名可以不一样,但是类型一定要一致
insert into $table_name 
[(column,...)]
select column,...|from $other_table_name;

  • 更改表数据

``
update $table_name set column=$value where column=$condition;


- 删除表数据

delete from $table_name where column=$value;


- 非空约束

create table $table_name(
column_name datatype not null,
...
)


- 主键约束

create table $table_name (
column_name datatype primary key,
...
)

多字段组合主键约束

create table userinfo(
id number(6,0),
username varchar2(),
userpwd varchar2(32),
constraint pk_userinfo_id_username primary key (id,username);
)

查看表的主键名称 注意大写

select constraint_name from user_constraints where table_name='USERINFO';

禁用开启主键约束

alter table userinfo disable|enable contraint pk_userinfo_id_username;

删除约束

alter table userinfo drop contraint pk_name;

等效上面

alter table userinfo drop primary key;


- 外键约束

create table $table_slave_name (
column_name datatype references $table_master_name(column_primary),
...
)

s

相关文章

  • oracle常用基础命令

    使用系统用户登录 查看登录的用户 启用scott用户 创建表空间 查看表空间的路径 修改表空间 删除表空间 创建表...

  • Oracle DBA常用命令书目录

    Oracle DBA常用命令之查看表空间的名称及大小: Oracle DBA常用命令之查看表空间物理文件的名称及大...

  • Oracle 常用运维命令整理

    Oracle 常用运维命令整理 一、oracle建库与删库命令 (1)oracle11g 建库(一般习惯配置gdb...

  • SSH <一>

    一、介绍 SSH 基础介绍 二、常用命令 SSH 常用命令

  • Linux系统基础命令汇总

    Linux系统学习,总结汇总了linux系统下基础常用的命令: 一.Linux系统基础常用命令 1.命令da...

  • 大数据技术学习路线

    一、大数据技术基础1、linux操作基础 linux系统简介与安装linux常用命令–文件操作linux常用命令–...

  • Oracle - sql基础命令

    SQLplus基础命令win+R(cmd) 输入 sqlplus输入用户名/口令-或者简化输入:sqlplus s...

  • Oracle 基础命令合集

    一 、视图 1、 创建视图 (联立两个表) 二、主键 1、 添加联合主键 后面补充 也可以在建表的时候就制定联合主...

  • Mongodb 常用命令汇总 2020-08-14

    [toc] Mongodb 常用命令 基础操作命令 索引命令 数组命令 库和集合命令 循环命令 命令总结

  • oracle sql*plus常用命令

    此文章出自: Ruthless 二、oracle sql*plus常用命令一、sys用户和system用户Orac...

网友评论

      本文标题:oracle常用基础命令

      本文链接:https://www.haomeiwen.com/subject/cuwkrxtx.html