Oracle table creation, table modification, data manipulation

Oracle table creation, table modification, data manipulation

1. Create the table, design the field data type by yourself, and design the corresponding constraints
1) Student information table, including fields: student ID, name, age, gender
2) Teacher table, including fields: teacher number, teacher name
3) Account table , Contains fields: course number, course name, teacher number
4) Results table, contains fields: student number, course number, grade

2. Table modification
1) Change the name of the student information table to another name
2) Add an address field to the student information table
3) Change the data type of the address field to other data types

3. Data operation
1) New sentence for student information table
2) Update sentence for
student information table 3) Delete sentence for student information table

--create the user 
--用户名
create user student11
--密码
identified by "123456";
--授予权限
grant connect,resource to student11;
-- revoke取消权限
--查询当前用户
select user from dual;

--创建学生表student
create table student(
    sno  varchar2(20) primary key,--学号
    sname varchar2(20) not null,--姓名
    ssex varchar2(20) not null,--性别
    sage number(5) not null--年龄
)

select *from student11.student;

--创建教师表teacher
create table teacher(
    tno varchar2(20) primary key,--教师编号
    tname  varchar2(20) not null--教师姓名
)

select *from student11.teacher;

--创建科目表subject
create table subject(
    sjno varchar2(20) primary key,--课程编号
    sjname  varchar2(20) not null,--课程名字
     tno  varchar2(20) not null --教师   
)
--创建成绩表score
create table score (
      sno  varchar2(20) not null,--学号 
      sjno varchar2(20) not null ,--课程编号
      scscore number(10,2) not null ,--成绩
      constraint pk_sc primary key(sno, sjno)--主键约束
)
--修改表名
alter table student rename to student01;
--查询 student01
select *from student11.student01;
--在学生信息表(student01)添加字段
ALTER TABLE student01 ADD sdep varchar(100);--院系
--查询 修改后的student01
select *from student11.student01;
--将 添加的字段改为varchar2类型
ALTER TABLE student01 MODIFY sdep varchar2(100);
--学生信息表新增信息(插入数据记录)
insert into student01(sno,sname,ssex,sage,sdep)
values('1','zi_chuan','男',22,'大数据学院');
--查询结果 
select * from student01 st01 where st01.sno='20170505210';
--更新学生表信息
update student01 st01
             set st01.sname='manxinlong',st01.sdep='信息工程学院';
             
--查询更新之后的结果 
select * from student01 st01 where st01.sno='20170505210';
--在删除前增加一条学生表的数据
insert into student01(sno,sname,ssex,sage,sdep)
values('20180505222','张三','男',22,'土木学院');
--查询张三
select * from student01 st01 where st01.sno='20170505211';
--删除张三
delete from student01 st01 where st01.sname='张三';
commit;
--删除后再次查询删除的张三数据为空
select * from student01 st01 where st01.sno='20180505222';

Guess you like

Origin blog.csdn.net/LL__Sunny/article/details/108782940