oracle常用SQL

oracle常用SQL

表(table)

创建

-- Create table
create table t_table_name
(
  _id  NUMBER(10) primary key,
  _column_1      NUMBER(10)
);
-- Add comments to the table 
comment on table t_table_name
  is '表备注';
-- Add comments to the columns 
comment on column t_table_name.column_1
  is '列备注';

删除

drop table t_table_name;

修改


索引(index)

创建

-- Create index 
create index index_name on table_name(column_name);

删除

drop index index_name;

修改


序列(sequence)

创建

-- Create sequence 
create sequence seq_name
minvalue 1
maxvalue 9999999999
start with 1
increment by 1
cache 10;

删除

drop sequence seq_name;

修改


多用户

创建用户

用户名是A,密码是password

create user A identified by password;

授权

授予connect权限

grant connect to A;

授予select权限

给指定用户的表或者视图授予select(只读)权限,其中t_test是表名或者视图名

grant select on B.t_test to A;

注意:我在这里只是授予A用户对视图的select 权限,所以当你以该用户登录后是看不到视图的,可以通过下面的语句来查询,如果想看到视图,你需要给它一个show的权限

select * from B.t_test;

创建同义词

创建表同义词(别名),其中t_test是B.t_test的别名

create or replace synonym t_test for B.t_test;

现在就可以用select * from t_test直接查询B.t_test的数据。

原文地址:https://www.cnblogs.com/jimmyfan/p/11598810.html