Oracle 增刪列,為列增加注釋,修改主鍵等

2021-09-30 06:46:44 字數 1781 閱讀 6792

drop table study;

drop table student;

drop table course;

/create table  student

(sid varchar(10),

sname varchar(30),

primary key (sid));/

create table course

(cid varchar(10),

cname varchar(50),

primary key (cid));/

create table study

(sid  varchar(10),

cid  varchar(10),

score integer  default 0 check (score between 0 and 100),

constraint pk_study  primary key (sid)  --注意此處設定主鍵約束名,便於後面修改表的主鍵);/

commit;/

select * from student;

select * from study;

/--以表 student,study,score 為例

--1.增加列

alter table student  add (*** varchar2(2) default '女',age integer,address varchar(100)) ;

/--2.修改列定義

alter table student modify *** varchar2(4)  default '男';

/--3.刪除列

alter table student drop column address;

/--4.修改列名

alter table student rename column   sid to sno;

/alter table student rename column   sno to sid;

/--5.修改表名

rename study to learn;

/rename learn to study;

/--6.增加注釋

-- 給表新增釋

comment on table study is '學習資訊表';

/--給列新增注釋

comment on column study.sid is '學員編號';

/--7.增加外來鍵關聯

alter table study add constraint fk_study_r_student_s foreign key (sid) references  student(sid); /

--8.修改主鍵

--查詢主鍵約束名

select t.constraint_name from user_constraints t where table_name='study' and constraint_type='p' and rownum<2;

/--刪除主鍵約束

alter table study drop constraint  pk_study 

/  

--新增主鍵

alter table study add constraint pk_study  primary key (cid,sid); 

/commit;/

select * from student;

select * from study;

select * from course;/

ORACLE中給表 列增加注釋以及讀取注釋

在oracle中給表 列增加注釋以及讀取注釋 1 給表填加注釋 sql comment on table 表名 is 表注釋 2 給列加注釋 sql comment on column 表.列 is 列注釋 3 讀取表注釋 sql select from user tab comments wher...

Oracle 增加修改刪除欄位與新增注釋

新增欄位的語法 alter table tablename add column datatype default value null not null 修改欄位的語法 alter table tablename modify column datatype default value null ...

Oracle 增加修改刪除欄位與新增注釋

新增欄位的語法 alter table tablename add column datatype default value null not null 修改欄位的語法 alter table tablename modify column datatype default value null ...