-->
数据库对象:据库对象可以被看成任何通过使用SQL的create语句创建后即存在的数据库项。
TIPS:数据库对象的大小和形式可能有很大的差别。
常见的数据库对象:表(table)、视图(View)、实体化视图(materialized view)、索引(index)、触发器(trigger)、同义词(synonym)、序列(sequence)、角色(role)、函数、过程和包。
建立用户赋权
SQL> create user sun
2 identified by super
3 temporary tablespace temp ;
User created.
SQL> grant connect,resource to sunchao
2 ;
Grant succeeded.
SQL> conn sun
Enter password:
Connected.
建表
SQL> create table NEWSPAPER (
2 Feature varchar2(15) not null,
3 Section char(1),
4 Page NUMBER);
Table created.
向表中添加数据:
SQL> insert into newspaper values ('National','A',1);
1 row created.
SQL> insert into newspaper values ('Sports','D',1);
1 row created.
SQL> insert into newspaper values ('Editorials','A',12);
1 row created.
选择数据:
SQL> select * from newspaper;
FEATURE S PAGE
--------------- - ----------
National A 1
Sports D 1
Editorials A 12
查看表的定义:
SQL> desc newspaper;
Name Null? Type
----------------------------------------- -------- ----------------------------
FEATURE NOT NULL VARCHAR2(15)
SECTION CHAR(1)
PAGE NUMBER
打开或关闭反馈功能(feedback)
以下是打开反馈时的输出:
SQL> set feedback on
SQL> select * from newspaper;
FEATURE S PAGE
--------------- - ----------
National A 1
Sports D 1
Editorials A 12
3 rows selected.
建立视图,视图允许用户查看数据库中的一个或多个表的定制选项,在访问视图时,存储的SQL语句被执行,然后用户就可以使用查询的结果。
SQL> create view newspaperview as select * from newspaper;
View created.
SQL> select * from newspaperview;
FEATURE S PAGE
--------------- - ----------
National A 1
Sports D 1
Editorials A 12
3 rows selected.
建立唯一性索引
SQL> create unique index test on newspaper (feature);
Index created.
删除索引
SQL> drop index test;
Index dropped.
给表添加主键
SQL> alter table newspaper
2 add constraint new_feature primary key (feature);
Table altered.
SQL> create table NEWSPAPER (
2 Feature varchar2(15) not null,
3 Section char(1),
4 Page NUMBER);
Table created.
向表中添加数据:
SQL> insert into newspaper values ('National','A',1);
1 row created.
SQL> insert into newspaper values ('Sports','D',1);
1 row created.
SQL> insert into newspaper values ('Editorials','A',12);
1 row created.
选择数据:
SQL> select * from newspaper;
FEATURE S PAGE
--------------- - ----------
National A 1
Sports D 1
Editorials A 12
查看表的定义:
SQL> desc newspaper;
Name Null? Type
----------------------------------------- -------- ----------------------------
FEATURE NOT NULL VARCHAR2(15)
SECTION CHAR(1)
PAGE NUMBER
打开或关闭反馈功能(feedback)
以下是打开反馈时的输出:
SQL> set feedback on
SQL> select * from newspaper;
FEATURE S PAGE
--------------- - ----------
National A 1
Sports D 1
Editorials A 12
3 rows selected.
建立视图,视图允许用户查看数据库中的一个或多个表的定制选项,在访问视图时,存储的SQL语句被执行,然后用户就可以使用查询的结果。
SQL> create view newspaperview as select * from newspaper;
View created.
SQL> select * from newspaperview;
FEATURE S PAGE
--------------- - ----------
National A 1
Sports D 1
Editorials A 12
3 rows selected.
建立唯一性索引
SQL> create unique index test on newspaper (feature);
Index created.
删除索引
SQL> drop index test;
Index dropped.
给表添加主键
SQL> alter table newspaper
2 add constraint new_feature primary key (feature);
Table altered.

发表评论