上一期讲了 如何创建表,例如我们创建了一个 名为 t_customer 的表,格式为下:
create table t_customer(
cust_id int primary key,
cust_name varchar(20),
cust_gender char(3),
cust_age int,
cust_birthday date,
cust_height number(3,2),
cust_phone varchar(15),
cust_addres varchar(30),
cust_note varchar(30)
);
今天我们就用这个表数据来进行操作
一、插入表数据
格式:
insert into 表名 values();
操作:
insert into t_customer (CUST_ID, CUST_NAME, CUST_GENDER, CUST_AGE, CUST_BIRTHDAY, CUST_HEIGHT, CUST_PHONE, CUST_NOTE)
values (11, '小磊', 'M ', 22, to_date('08-12-2000', 'dd-mm-yyyy'), 1.85, '13193366630', '吴彦祖');
按照上面的表格式进行对应的数据插入,我们得到新的表数据
二、 删除数据
格式:
(1)drop table 表名 ;删除表(整个表全删除)
如:
drop table t_customer;
删除后 整个表用select * from 查看时,已经不在存在了
(2)只删除表数据(表依旧存在)
delete from 表名
如:
delete from t_customer;
用select * from查看依旧可以看到表格式在
三、修改
alter table 表名 (操作符)如: add/rename/drop.....等
(1) rename改名
格式:
alter table 表名 rename column 旧名字 to 新名字;
比如 我们修改age的这一列
操作:
alter table t_customer rename column cust_age to cust_age01;
(2)新增一列
格式:
alter table 表名add 列名 类型;
操作:
alter table t_customer add cust_note01 varchar(30);
(3)删除一列
格式:
alter table 表名 drop column 列名;
操作:
alter table t_customer drop column cust_note01;
已经删除了上面的note01。
四、排序
按照上面的表格式进行对应的数据插入,我们 先插入多条数据 则得到多条数据
利用 order by 进行排序操作:
order by 默认为升序,但是有操作关键字(desc 降序,asc 升序)。
例如:
我们在此处用年龄进行排序,默认为升序
select * from t_customer order by cust_age;
进行多个参数来排序:
同时 用参数 1来降序排序,如同参数1相同,则默认用参数2来升序排序
select cust_age, cust_height, cust_name from t_customer order by 1 asc,2 asc;
五、起别名
格式:
(1)
select cust_name 别名 , cust_age from t_customer order by cust_age;
select cust_name 姓名 , cust_age from t_customer order by cust_age;
(2)
在需要起别名的 目标后加 空格 然后 加别名即可,但是如果别名是 关键字或者函数名,
则别名需要带双引号 “别名”
select cust_name "别名", cust_age from t_customer order by cust_age 别名;
(3)利用 as起别名,但是as不能给表起别名
select cust_name as "别名", cust_age from t_customer order by cust_age 别名;
六、 提交
只需要进行 commit提交即可,在提交前如果进行了数据修改操作,则上方的会有数据类型标识显示,进行commit提交后 则会将数据保存到服务端
commit
此处提交完毕则自动保存