第三章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用户下
修改表
添加一列
Altertable stu add(tel number(11));
修改字段的长度,类型
Altertable stu modify(tel number(10));
修改字段名字 tel———》phone
Altertable stu rename column tel tophone;
删除字段
Altertable stu drop column phone;
修改表名
Altertable stu rename to stu2;
Renamestu to stu2;(建议用这种方式)
删除表
Droptable stu2;
数据库表的增删改查
添加数据 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);
查询数据 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;
删除数据 delete
Deletefrom stu where id=1001;
Delete from stu;(删除表中所有数据,可以找回数据)
Truncate table stu;(删除表中所有数据,不可以找回数据)
数据库约束
非空约束not null
主键约束primary key
唯一键约束unique
外键约束 foreignkey