您的位置:首页 > 数据库

oracl数据库的常用知识

2015-08-14 00:19 239 查看
cmd的解锁命令

sqlplus / as sysdba

SQL>alter user scott acount unlock;使其未锁定

SQL>alter user scott acount identified by 密码;修改其密码

SQL> conn scott/密码;根据新的密码和用户名连接上数据库;

//创建表

create table 表名(列名 类名类型,列名 类名类型,列名 类名类型,,,,,);

//更新表

update 表名 set 列名=修改内容 where 主键=对应的值;

//修改表结构

alter table 表名 add 增加的列名 列名类型;

//删除表中某条记录

delete from 表名 where 列名 = 值;

//删除表

drop table 表名;

//删除表中的某一列

alter table 表名 drop column 列名;

//删除主键约束

alter table 表名 drop primary key;

//添加主键约束

alter table 表名 modify (列名 列名类型 primary key);

//添加唯一约束

alter table 表名 add constraint 自定义约束名 unique(列名);

//删除唯一约束

alter table 表名 drop constraint 约束名;

//添加检查约束

alter table 表名 add constraint 约束名 check (sex in('男','女'));

//约束重命名

alter table 表名 rename constraint 原约束名 to 改后的约束名;

//默认约束

alter table 表名 modify 列名 列名类型 default 约束条件;

//创建学生表与课程表的映射表-----联合主键

create table student (

sno varchar2(20),

constraint fk_student _sno references student (sno),

cno varchar2(20),

constraint fk_student _cno references course (cno),

grade number consteaint ck_grade check(grade between 0 and 100),

constraint fk_cno_sno primary key (sno,cno)

);

//标的简单查询

select * from 表名 ;

//去掉重复行查询

select distinct 列名 from 表名;

//查看表结构

desc 表名;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: