1、创建 产品信息表(产品编号, 产品名称, 生产日期, 销售价格) 主键:产品编号
方式一:先建表,再设置主键
create table product_info
(
product_id varchar2(10)
,product_name varchar2(100)
,made_date date
,price number(10)
);
alter table product_info add constraint pk_product_info primary key(product_id);
方式二:建表时,直接设置主键
create table product_info
(
product_id varchar2(10) primary key
,product_name varchar2(100)
,made_date date
,price number(10)
);
2、往 1 中创建的表插入数据
insert into product_info
values('p1234','苹果14手机',to_date('20221013','yyyymmdd'),9000);
insert into product_info
values('p1235','huawei-p50',to_date('20221013','yyyymmdd'),9000);
commit;
3、修改产品信息表
update product_info t
set t.price = 1000
where t.product_id = 'p1235';
commit;
4、删除表中的数据
delete from product_info t
where t.product_id = 'p1234';
commit;
select * from product_info;
5、emp 表练习
查询出30部门中工资大于1500的员工的工号,姓名,工资,部门编号
select t.empno
,t.ename
,t.sal
,t.deptno
from emp t
where t.deptno = 30
and t.sal > 1500;
查询 salesman 这个岗位中,入职日期早于1982年1月1号的员工的工号,姓名,岗位名称,入职日期
select t.empno
,t.ename
,t.job
,t.hiredate
from emp t
where t.job = 'salesman'
and t.hiredate < to_date('19820101','yyyymmdd');
找出30部门中入职日期早于1982年1月1号的员工的所有信息或者岗位是 manager 的员工中工资大于2900 的员工的所有信息
select t.empno
,t.ename
,t.job
,t.mgr
,t.hiredate
,t.sal
,t.comm
,t.deptno
from emp t
where (t.deptno = 30 and t.hiredate < to_date('19820101','yyyymmdd'))
or (t.job = 'manager' and t.sal > 2900);