标签:
常用的数据库对象
表:基本的数据存储对象,以行和列的形式存在,列是字段,行是记录。
数据字典:就是系统表,存放数据库相关信息的表。
约束条件:执行数据校验,保证了数据完整性的对象。
视图:一个或者多个表数据的逻辑显示。
索引:用于提高查询的性能。
同义词:对象的别名。
1.
表的创建,增加表字段,修改表字段和删除表字段。
----------------------创建表-----------------------
create table test6(
tid number(2),
tname varchar2(20)
);
---------------------增加表字段--------------------
alter table test6
add(tage number(3));
---------------------修改表字段--------------------
alter table test6
modify(tname varchar2(30));
---------------------删除表字段--------------------
alter table test6
drop column tage;
---------------------察看表字段--------------------
desc test6
---------------------创建表序列--------------------
create sequence tid_seq
increment by 1
start with 1
nomaxvalue
nocycle
cache 1;
---------------------truncate----------------------
truncate table table_name:彻底删除表记录,而delete是可选的。(只是删除数据,而不是删除表)
2.
数据字典表:被oracle数据库和维护的表,也就是系统表;
包括了数据库自身的信息,被用于支持数据库的运行。
----------------查看被用户拥有的表-------------
select table_name from user_tables;
----------查看用户拥有的所有对象类型-----------
select distinct object_type from user_objects;
------------查看所有用户拥有的表---------------
select * from dba_tables;
3.保证数据完整性的约束条件
3.1.-----------not null------------------------
create table test6(
tid number(2) not null,
tname varchar2(20)
);
3.2.----------Uniqe key 唯一键-----------------
create table test6(
tid number(2),
tname varchar2(5),
tmail varchar2(20),
constraint tmail_uk unique(tmail)
);
insert into test6 values (1,'aa232','abc@abc.com');
insert into test6 values (2,'tyur','abc@abc.com');
3.3.----------Primary key 主键-----------------
create table test6(
tid number(2),
tname varchar2(5),
constraint tid_pkey primary key(tid)
);
insert into test6(tid,tname) values (1,'abc');
insert into test6(tid,tname) values (1,'abc');
3.4.----------foreign key 外键-----------------
create table test7(
tmpid number(2),
tid number(2),
tname varchar2(5),
constraint tid_fkey foreign key(tid)
references test6(tid)
);
insert into test7(1,1,'bbc');
delete from test6 where tid = 1;
//删除不成功
delete from test7 where tid = 1;
//先删除外键
delete from test6 where tid = 1;
//在删除主键
3.5.----------check约束-----------------
create table test8(
tid number(2),
tscore number(3),
constraint tscore_chk check(tscore >= 0 and tscore <= 100)
);
insert into test8 values (1,101);
违反检查约束条件
insert into test8 values (1,100);
3.6.----------修改表约束:增加-----------------
create table test6(
tid number(2),
tname varchar(20)
);
alter table test6
add constraint tid_pk1 primary key(tid);
3.6.----------修改表约束:卸载-----------------
alter table test6
drop constraint tid_pk1;
4.索引
索引:加快查询速度,类似书的目录.
表中所设定的主键即为索引,如果觉得条件不够,可以追加.
create index indexName on talbeName(columnName,...);
create index test6Index on test6(tname);
删除索引:
drop index test6Index;
5.视图
功能:简化查询语句.
只允许用户通过视图来看到表中的一部分数据.
5.1创建视图
insert into test6 values (1,'aaa');
insert into test6 values (2,'bbb');
insert into test6 values (3,'ccc');
insert into test6 values (4,'ddd');
create view test6_view as select * from test6 where tid < 4 with read only;
select * from test6_view;
delete from test6_view where tid = 1;
5.2卸载视图
drop view test6_view;
5.3修改视图
create or replace view test6_view as select * from test6 where tid < 4 with read only;
6.同义词
为对象起别名
create synonym tv for test6_view;
select * from tv;
drop synonym tv;


档案
日志
相册
视频



评论
想第一时间抢沙发么?