天天看點

SQL語句複習【專題六】

SQL語句複習【專題六】

使用者 + 建立表 

--建立一個新的使用者,然後給新的使用者建立一張表,然後給表中添加一些資料。查詢表中的資料
--建立使用者需要比較大的權限 DBA 
create user dilraba identified by 123456
--使用者剛剛建立沒有任何的權限,需要授予權限。
--通過授予角色的方式給使用者授予權限,一個角色是一組權限的集合
--Resource  connect
--授予使用者權限
grant resource, connect to dilraba
--删除角色的權限
revoke connect from dilraba
---删除使用者
drop user yang
--修改使用者密碼
alter user dilraba identified by 654321

--建立表格
--建立一張用來存儲學生資訊的表
--字段包含學号、姓名、性别,年齡、入學日期、班級,email等資訊
create table student(
       sno varchar2(6),
       sname varchar2(12),--四個中文
       sex char(3) default \'男\',
       age number(3),
       sdate date,
       clazz varchar2(10),
       email varchar2(20)
);
select * from student

--插入測試資料 DML
insert into student values(\'000001\',\'徐志摩\',\'男\',30,sysdate,\'c0001\',\'[email protected]\');
insert into student  (sno,sname,age,sdate,clazz,email) values(\'000002\',\'徐志摩\',30,sysdate,\'c0001\',\'[email protected]\');
insert into student values(\'000001\',\'林徽因\',\'女\',30,sysdate,\'c0001\',\'[email protected]\');
insert into student values(\'000004\',\'陸小曼\',\'女\',29,sysdate,\'c0001\',\'[email protected]\');
commit
--更新資料
update student set sno=\'000003\' where sname=\'林徽因\';
--删除資料
delete from student where sno=\'000001\';      

對表的其他正常操作

---對表的以及表的結構的操作
--給表格添加字段
alter table student add (birthday date)--新字段的值為 null
alter table student add (score number(3) default 100)
--删除表格的指定的字段
alter table student drop column birthday
--修改表格指定的字段名稱
alter table student rename column sex to gender
--修改表格的字段的資料的類型
alter table student modify (gender varchar2(3))
--重命名表
rename student to stu
--删除表--XE 版本比較簡單。資源回收筒的功能不能使用,使用 drop table 表會删除到資源回收筒中。
drop table stu
--檢視資源回收筒
select * from recyclebin
--如何從資源回收筒還原表格
flashback table stu to before drop
--删除資源回收筒中的某個表
purge table stu
--直接删除不進入資源回收筒
drop table stu purge
--清空資源回收筒
purge recyclebin