mysecondpractice

insert into bonus values(‘周末‘,‘cooker‘,4000,1000);
insert into bonus values(‘周一‘,‘cooker‘,4000,1000);
insert into bonus values(‘周二‘,‘cooker‘,4000,1000);
insert into bonus values(‘周三‘,‘cooker‘,4000,1000);
insert into bonus values(‘周四‘,‘cooker‘,4000,1000);
insert into bonus values(‘周五‘,‘cooker‘,4000,1000);
select * from bonus;
insert into bonus(ENAME,JOB,SAL,COMM)(select * from bonus);--将后表内容添加给前表
delete bonus where ENAME = ‘周末‘;
update bonus set sal =5000 where ENAME =‘周一‘;
--DDL语句之创建表
create table person
       (I_ID NUMBER(18),
        INAME VARCHAR(7),
        IAGE NUMBER(2),
        constraint "PRE_I_ID" PRIMARY KEY("I_ID"));--怎么定义约束???
insert into person values(001,‘周末‘,16,‘女‘,‘高管‘);
insert into person values(002,‘周末‘,16,‘女‘,‘高管‘);
insert into person values(003,‘周末‘,16,‘女‘,‘高管‘);
insert into person values(004,‘周末‘,16,‘女‘,‘高管‘);
insert into person values(005,‘周末‘,16,‘女‘,‘高管‘);
delete person where ISEX =‘女‘;
select distinct person.i_id from person;
select * from person;
create table newgrid
    AS
       select * from bonus where bonus.sal =4000;--将一个表中的内容转移到新表
--更新表
alter table person
      ADD
            (ISEX VARCHAR(2),
             JOB VARCHAR(8));
alter table person
      MODIFY
            (INAME VARCHAR2(4));
--删除表(delect和truncate)
drop table person;
truncate table person;
--表的连接(两表间不一定要有键与键的联系)
select emp.ename,emp.job,bonus.comm from emp,bonus;--从多个表中查询信息,然后信息组合为一个新表
select s.s#,sc.* from student s,sc where s.s#=sc.s#;--等值查询
select s.s#,sc.* from student s,sc where s.s#=sc.s# and sc.c#=01;--多个条件约束
select s.*,sc.* from student s,sc where s.s#(+)=sc.s#;                                /*外连接*/
select s.*,sc.* from student s,sc where s.s#=sc.s#(+);--加号放哪边和主外键有关,加号在哪边表就加在对面条件上        /*外连接*/
select sc.*,student.s# from sc join student on student.s#=sc.s#;--细心点啊啊啊!!
select emp.*,dept.* from emp,dept where emp.deptno(+)=dept.deptno;
select emp.*,dept.* from emp,dept where emp.deptno=dept.deptno(+);
select max(sal) from emp where emp.empno between 7000 and 7500;
--商品信息/会员信息/购物车/历史订单
drop table commodity;
create table commodity
       (CNAME VARCHAR2(16),
        BRAND VARCHAR2(16),
        PRICE NUMBER(4),
        VARIETY VARCHAR2(16));
insert into commodity values(‘开心果‘,‘三只松鼠‘,138,‘坚果‘);
insert into commodity values(‘蜜饯‘,‘三只松鼠‘,138,‘坚果‘);
insert into commodity values(‘梅果‘,‘三只松鼠‘,138,‘坚果‘);
insert into commodity values(‘鳕鱼肠‘,‘三只松鼠‘,138,‘坚果‘);
insert into commodity values(‘早餐饼‘,‘三只松鼠‘,138,‘坚果‘);
select * from commodity;
drop table member;
create table member
       (MNAME VARCHAR2(4),
        M_ID NUMBER(9),
        M_PHONE NUMBER(11),
        M_RANK VARCHAR2(10));
insert into member values(‘周末‘,001,123456788,‘平民‘);
insert into member values(‘周一‘,002,123456788,‘贵族‘);
insert into member values(‘周二‘,003,123456788,‘天子‘);
insert into member values(‘周三‘,004,123456788,‘大臣‘);
insert into member values(‘周五‘,005,123456788,‘上帝‘);
select * from member;
drop table shoppinglist;
create table shoppinglist
       (S_CMATION VARCHAR(12),
        SNAME VARCHAR2(4),
        SRECORD VARCHAR(12),
        SUM_PRICE NUMBER(5));
insert into shoppinglist values(‘三只松鼠‘,‘你猜‘,‘谁买过‘,800);
insert into shoppinglist values(‘三只松鼠‘,‘你猜‘,‘谁买过‘,800);
insert into shoppinglist values(‘三只松鼠‘,‘你猜‘,‘谁买过‘,800);
insert into shoppinglist values(‘三只松鼠‘,‘你猜‘,‘谁买过‘,800);
select * from shoppinglist;
drop table historyorder;
create table historyorder
       (H_INFORMATION VARCHAR(12),
        H_TIME DATE);
insert into historyorder values(‘买过的‘,to_date(‘02-11-2015‘,‘dd-mm-yyyy‘));
insert into historyorder values(‘买过的‘,to_date(‘02-11-2016‘,‘dd-mm-yyyy‘));
insert into historyorder values(‘买过的‘,to_date(‘02-10-2015‘,‘dd-mm-yyyy‘));--所有日期都应是此格式;
insert into historyorder values(‘买过的‘,to_date(‘04-04-2015‘,‘dd-mm-yyyy‘));
select * from historyorder;
select s.srecord||c.cname from shoppinglist s,commodity c;
select emp.empno||emp.job from emp;
delete dept where dept.deptno=10;--挂了的原因违反完整约束条件
delete emp where emp.deptno=10;
时间: 2024-10-15 01:56:08

mysecondpractice的相关文章