表管理

来源:互联网 发布:淘宝首页装修要多少钱 编辑:程序博客网 时间:2024/05/22 00:54

第三章 Oracle 表管理复习

一数据类型

  字符类型:char,varchar2, long

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

  日期型:date 19-9月-16,timestamp

  Lob数据类型:blob,clob,bFile

  Rowid数据类型

二表管理

l  表的创建

Stu:id,name,age

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

快速复制一张表,复制emp

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

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

l  修改表

1.      添加一列

Alter table stu add(telnumber(11));

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

Alter table stu modify(telnumber(10));

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

Alter table stu rename columntel to phone;

4.      删除字段

Alter table stu drop columnphone;

5.      修改表名

Alter table stu rename to stu2;

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

6.      删除表

Drop table stu2;

l  数据库表的增删改查

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);

 

2.      查询数据 select

Select * from stu;

Select * from stu where name=’ada’;

Select name,age from stu;

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

3.更新数据 update

   Updatestu set age=20 where id=1001;

   Updatestu set age=21,name=’tina’ where id=1002;

4.      删除数据 delete

Delete from stu where id=1001;

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

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

l  数据库约束

非空约束 not null

主键约束 primary key

唯一键约束 unique

外键约束 foreign key