跟著 Rice學(xué)數(shù)據(jù)庫(kù)
---增刪改查---
--一己英、創(chuàng)建
create table t1(
id int not null,
name varchar2(5) not null,
tel int not null
);
--二冷离、修改表
--修改表名
rename t1 to tb1;
--增加字段
alter table tb1 add sex char(4);
--修改字段名
alter table tb1 rename column tel to tell;
--刪除字段
alter table tb1 drop column sex;
--修改字段
alter table tb1 modify name int;
alter table tb1 add sex char(4);
alter table tb1 modify sex int;
--三、插入數(shù)據(jù)
insert into tb1(id,name,tell) values ('1','linux','1234');
select id,name,tell from tb1;
insert into tb1(id,name,tell) values ('1','linux','1234');
--過(guò)濾重復(fù)的元素
select distinct *from tb1;
--三题禀、更新數(shù)據(jù)
update tb1 set tell = '12345' where tell = '1234';
select *from tb1;
alter table tb1 drop column name;
--四、刪除表
--刪除表中的所有數(shù)據(jù)废膘,速度比delete快很多
truncate table tb1;
--五旬薯、刪除用戶
--刪除用戶
drop user gary;
--若用戶擁有對(duì)象,無(wú)法直接刪除用戶敛劝,需要先刪除用戶所有對(duì)象再刪除用戶
drop user gary cascade;
drop user gary;
--六余爆、查看所有數(shù)據(jù)庫(kù)
select instance_name from V$instance;
--查看當(dāng)前用戶所有表
--(user_tables是單用戶級(jí)別,all_tables所有用戶級(jí)別夸盟,dba_tables全局級(jí)別包括系統(tǒng)表)
select table_name from user_tables;
--查看表結(jié)構(gòu)(只識(shí)別sql-只在命令行中使用)
desc tab1;
--查看當(dāng)前登錄的用戶
select user from dual;
--show user;命令行使用
--查看oracle版本號(hào)
select * from v$version;
--查看當(dāng)前環(huán)境是pdb還是cdb(12c用11g用不到)
select name,cdb,open_mode,con_id from v$database;