第二次Oracle上机任务.docx
文本预览下载声明
百度网盘搜索:/index.html(用于搜索下载软件,如Oracle 10g等)视频1:/s/1qW7JGQC视频2:/s/1ntyw1lf 2选1我的数据库名字: orcl9 密码:o1234561、模式2、创建表3、表约束4、修改表5、删除表1、模式set oracle_sid=orcl9sqlplus /nolog1)进入同名模式(首次使用可能需要设置见附录,我设置scott用户的密码 ake)connect scott/akeshow user2)进入sys模式connect /as sysdbashow user3)进入public模式connect sys/o123456 as sysopershow user2、创建表先进入同名模式(普通用户没权限建表)connect scott/ake1)建表,表名:studentCreate table student(Sno number(6) constraint s_PK primary key,Sname varchar2(10) not null,Sex char(2) constraint s_ck1 check(sex in (m,f)),Sage number(6,2),Constraint s_ck2 check(sage between 18 and 60));2)创建临时表Create global temporary table tran_temp(ID number(2) primary key,Name varchar2(20))On commit Delete rows; 3)利用子查询创建表Create table stu_select(S_no,S_name)AsSelect Sno,Sname From student where Sno 10;3、表约束1)添加唯一约束Alter table student add constraint P_UK Unique(Sname);2)删除唯一约束Alter table student drop Unique(Sname);3)约束状态禁用约束Alter table student disable constraint S_CK1;激活约束Alter table student enable constraint S_CK1;4)查询约束信息Select constraint_name,constraint_type,deferred,statusFrom user_constraints where table_name=STUDENT;‘STUDENT’一定要大写4、修改表1)添加新列Alter table studentADD(phone varchar2(10) );2)修改列的类型Alter table studentModify phone number;3)修改列名Alter table student rename column phone to phonumber; 4)删除列Alter table studentDrop (phonumber);5)表参数修改Alter table studentPctfree 30 pctused 60 ;6)表结构重组Alter table student move;7)表重命名Student 改为 new_studentRename student to new_student;New_student 改为 studentAlter table new_student rename to student;8)为表和列添加注释Comment on table student IS 学生信息表;Comment on column student.Sname IS 学生姓名;5、删除表Drop table student;附录:第一次使用scottOrcl9 设置为新密码设置为 ake新进入SYS模式,在此模式中修改 Scott连接scott更改密码输入新口令时窗口不显示输入字符
显示全部