oracle数据库小总结(2017年7月10日)

---数据库小总结---
1.数据库的基本常用数据类型

①varchar2(size)              //浮动长度字符类型:长度会改变,根据用户输入的值进行相应的长度改变,节省内存空间

②char(size)                //固定字符长度,如果用户输入的值得长度,不够size,则系统默认用空格代替

③number(1,2)              //数字类型,包含小数和整数(1.代表数字的总长度/位数  2.表示小数点后的长度/位数)

④date              //时间类型  sysdate(系统时间) to_date('输入的时间',‘时间的格式’)  时间格式一般YYYY-MM-DD

 

2.DDL 数据定义语言

2.1创建表

create table test1(
   test2 varchar2(20) primary key,              //primary key  主键(一个表只能有一个,且不能重复和为空)
   test3 number(5,2) not null,                  //not null  不能为空   null可以为空(默认约束为null)
   test4 char(10) not null,                     
   test5 date default(sysdate)                  //default 添加默认约束

);

 

2.2 进行对表的增加,修改,删除

alter table test1 add(test2 varchar2(20) not null);       //其中test1为表名 test2为增加的列名,not null为约束
alter table test1 modify(test2 vatchar2(20) not null);    //其中varchar2(20) 为修改后的属性 not null 约束根据以前写没写适当添加
alter table test1 drop(test2);                            // test2 为test1中删除的列名
drop table test1                         // 直接删除表test1
  

 

2.3 添加约束

alter table test add constraint fk_test1 foreign key(test1) refenerces test3(test1)  //添加外键约束,test3表中的test1列为其主键,test1为test表中的要添加的外键
alter table test add constraint ck_test1 check(条件)                                  //添加检查约束,赋值时的约束条件
alter table test add constraint un_test1 unique(test1)                               //唯一约束,不能重复,可以有一个为空的值

 

3.DML语言 数据操作语言

insert into test1(test2,3,4) values(2,3,4)         //给表进行赋值,test1为表名,Test2,3,4 为要添加的值得列名(不写默认顺序为创建表时的列的顺序) 2,3,4 为具体的值
update test set test2=xx where test2=xxx;          //修改(更新)test表中的数据,将符合条件的test2例的值改为xx(不写条件会默认修改整个test2列的值为xx)   
delete  from test where test1=xx              //同上,删除符合条件的test表中的test1列的值(默认删除test1列全部的值)

 

posted @ 2017-07-10 19:45  皇后  阅读(235)  评论(0编辑  收藏  举报