暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

第三章Oracle表管理

悦悦学姐 2021-05-25
313

第三章Oracle 表管理复习


一数据类型


字符类型:char,varchar2, long


数值型:number(3),number(5,2)


日期型:date19-9月-16,timestamp


Lob数据类型:blob,clob,bFile


Rowid数据类型


二表管理


表的创建


Stu:id,name,age


Create table stu (id number(5),name varchar2(20), age number(3));


快速复制一张表,复制emp


Create table emp1 as select * from emp;//在scott用户下


Create table emp1 as select * from scott.emp; 不在scott用户下


修改表


  1. 添加一列


Altertable stu add(tel number(11));


  1. 修改字段的长度,类型


Altertable stu modify(tel number(10));


  1. 修改字段名字 tel———》phone


Altertable stu rename column tel tophone;


  1. 删除字段


Altertable stu drop column phone;


  1. 修改表名


Altertable stu rename to stu2;


Renamestu to stu2;(建议用这种方式)


  1. 删除表


Droptable stu2;


  • 数据库表的增删改查


  1. 添加数据 insert into


Insert into stu values(1001, ‘ada’,18);


Insert into stu(id,name) values(1002, ‘ada2’);


Insert into stu(id,name,age) values(1003, ‘ada2’,null);


  1. 查询数据 select


Select * from stu;


Select * from stu where name=’ada’;


Select name,age from stu;


Select * from stu where age is null;(查询空数据)


3.更新数据update


Update stu setage=20 where id=1001;


Update stu setage=21,name=’tina’ where id=1002;


  1. 删除数据 delete


Deletefrom stu where id=1001;


Delete from stu;(删除表中所有数据,可以找回数据)


Truncate table stu;(删除表中所有数据,不可以找回数据)


  • 数据库约束


非空约束not null


主键约束primary key


唯一键约束unique


外键约束 foreignkey



文章转载自悦悦学姐,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论