oracle基础:创建表和设置主键,修改属性等

来源:互联网 发布:reveur 知乎 编辑:程序博客网 时间:2024/06/08 13:48
--练习数据库基础;创建表和设置主键,修改属性等
create table book(
  book_id  number(10),--id
  book_name varchar2(10),--名称
  book_author varchar2(20),--作者
  book_publish_time  varchar2(20),--出版时间
  book_price  number(10),--价格
  book_introduction varchar2(200)--介绍
) tablespace TESTSPACE;


--设置主键    constraint :约束
 alter table book add constraint PK_ID primary key(book_id);


--添加和删除列
 alter table book add(
   book_remark  varchar2(200), --备注
   book_others  varchar2(200)--其他
 );


--删除列
  alter table book drop column book_remark;
  alter table book drop column book_others;
  
  alter table book drop(book_remark, book_others);


--修改表名称
  alter table book rename  to newbook;
  alter table newbook rename  to book;

--修改列名称
  alter table book rename column book_others to book_other;
  alter table book rename column book_other  to book_others;


--修改字段属性类型
 alter table  book modify book_introduction varchar2(200);


 --修改字段属性默认值
 alter table  book modify book_introduction default('关于书籍:');


--删除表

drop table book;










0 0
原创粉丝点击