oracle学习小记:建用户授权及各种数据库对象的创建(1)

| 暂无评论 | 暂无引用通告

-->

  数据库对象:据库对象可以被看成任何通过使用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.


暂无引用通告

发送引用通告网址: http://supersun.info/mt/mt-tb.cgi/744
如果您想引用这篇日记到您的Blog,请复制上面的链接,放置到您发表文章时的相应界面中。

发表评论

最新资源

  • IMG_1437.JPG
  • line.png
  • bar.png
  • perl_calander.jpg

关于此日记

此日记由 supersun 发表于 2007年9月26日 16:51

此Blog上的上一篇日记投资术语

此Blog上的下一篇日记萨伏伊别墅

首页归档页可以看到最新的日记和所有日记。