zoukankan      html  css  js  c++  java
  • Oralce常用命令

    用户管理

    为scott用户解锁

    1:解锁
      alter user scott account unlock;

    2: 更改密码
       alter user scott identified by tiger;

    3: 跳转
       connect sqlplus scott/tiger

    4  查询测试OK
        select * from emp;

    创建用户
    create user "username" identified by "userpassword";


    删除用户
    drop user "username" cascade;

    授权
    grant connect,resource,dba to "username";

    查看当前用户的角色
    select * from user_role_privs;
    select * from session_privs;

    查看当前用户的系统权限和表级权限
    select * from user_sys_privs;
    select * from user_tab_privs;

    查询用户表
    select username from dba_users;

    修改用户口令密码
    alter user "username" identified by "password";

    显示当前用户
    show user;


    表空间管理

    创建表空间
    create  tablespace data01 datafile 'd:/DATA01.DBF' size 10M;

    drop tablespace data01 including contents and datafiles;

    修改表空间大小
    alter database datafile 'D:/DATA01.DBF' resize 5M;

    增加表空间
    alter tablespace newccs add datafile 'D:/DATA02.DBF' size 40M;

    查看数据库文件
    select * from dba_table_files;
     
    查询当前存在的表空间
    select * from v$tablespace;

    表空间情况
    select tablespace_name,sum(bytes)/1024/1024 from dba_data_files group by tablespace_name;

    查询表空间剩余空间
    select tablespace_name,sum(bytes)/1024/1024 from dba_free_space group by tablespace_name;

    查看表结构
    desc table;



    约束管理

    非空约束
    创建非空约束
    create table test(id number(6) not null);

    添加非空约束
    alter table 表名 modify 列名 not null

    删除表中的非空约束
    alter table 表名 modify 列名 null

    主键约束 primary key

    创建primary key 约束
     create table test (id number(6) primary key);

    添加primary key 约束
     alter table 表名 add constraint 自定义约束名 primary key (列名)

    删除约束

    alter table 表名 drop constraint 约束名

    唯一约束 unique

    创建表时
    create table users(
     id number(6) primary key not null,
     name varchar2(20) unique);
    )

    添加unique约束
    alter table 表名 add unique(列名)


    检查约束 check

    创建表时
    create table users(
      id number(6) primary key not null,
      sex varchar2(2) check(sex='男' or sex='女') default '男';
    )

    添加check约束
    alter table users addsex varchar2(2) check(sex = '男' or sex = '女') default '男';

    外键约束 foreign key

    先创建一个班级表
    create  table class(
      classId number(6) not null primary key,
      className varchar2(10),
      count number(100)
    );

    再创建一个学生表
    create table student(
      studentId number(6) not null primary key,
      studentName varchar2(20),
      studentClass number(6) references class(classId)
    );

    添加外键约束
    alter table student add constraint fk_student_class referenc class (classId);

    级联删除约束
    添加外键时在外键后面加
    alter table student add constraint fk_student_class referenc class (classId) on delete cascade;

    删除外键时添加级联删除约束
    alter table 表名 drop primary key cascade;

    查看表的所有约束以下两种方法都可以
    select table_name,constraint_name,constraint_type from user_constraints
    where table_name='大写的表名'

    select table_name,constraint_name,constraint_type from dba_constraints
    where table_name='大写的表名'

  • 相关阅读:
    20191211 HNOI2017 模拟赛 问题A
    20191211 HNOI2017模拟赛 C题
    BZOJ 3681 Arietta
    netcore3.1中的Json操作
    netcore2.2出现的新特性HealthCheck
    MVC为什么要使用TagHelper?
    psql备份csv文件
    DataAnnotations的使用及细节处理
    记录一次mac安装node遇到的错误
    记录一次netcore3.0 code first使用迁移命令报错问题
  • 原文地址:https://www.cnblogs.com/ZHANYU/p/3631344.html
Copyright © 2011-2022 走看看