oracle基本操作

少年不言愁發表於2020-10-25

–建立表空間
create tablespace itheima
datafile ‘c:\itheima.dbf’
size 100m
autoextend on
next 10m;
– 刪除表空間
drop tablespace itheima;
–建立使用者
create user itheima
identified by itheima
default tablespace itheima;

–建立表
create table person(
pid number(11),
name varchar2(10),
);
–新增一列
alter table person add (gender number(1));
–修改列型別
alter table person modify gender char(1);
–修改列名稱
alter table person rename column gender to sex;
–刪除一列
alter table person drop column sex;

– 新增一條記錄
insert into person(pid,pname) values (1,‘小明’);

insert into person(pid,pname) values(2,‘小紅’);
commit;
–查詢
select * from person;
–修改
update person set pname=‘小馬哥’ where pid=1;
commit;
–刪除
delete from person;
drop table person;
truncate table person;–先刪除,再建立一張空表

序列 預設從1開始,依次遞增
create sequence s_person;
select s_person.nextval from dual;

–新增
insert into person(pid,pname) values(s_person.nextval,‘大明’);
commit;

相關文章