oracle 基本操作

-创建表格语法:
     create table 表名(
       字段名1 字段类型(长度) 是否为空,
        字段名2 字段类型       是否为空
);

1.表的修改

alter table 表名

add 列名 类型

drop column 列名

alter column 列名 类型

2.主键,外键

-增加主键
     alter table 表名 add constraint 主键名 primary key (字段名1);

-增加外键:
     alter table 表名
       add constraint 外键名 foreign key (字段名1)
         references 关联表 (字段名2);

在建立表格时就指定主键和外键

   create table T_STU (
      STU_ID               char(5)                         not null,
       STU_NAME             varchar2(8)                     not null,
      constraint PK_T_STU primary key (STU_ID)
);


主键和外键一起建立:
     create table T_SCORE (
       EXAM_SCORE           number(5,2),
       EXAM_DATE            date,
        AUTOID               number(10)                      not null,
       STU_ID               char(5),
       SUB_ID               char(3),
       constraint PK_T_SCORE primary key (AUTOID),
       constraint FK_T_SCORE_REFE foreign key (STU_ID)
        references T_STU (STU_ID)
)

 

posted @ 2011-01-03 20:09  JackGIS  阅读(231)  评论(0编辑  收藏  举报