1.完整的Oracle数据库通常由两部分组成:Oracle数据库和数据库实例。
1) 数据库是一系列物理文件的集合(数据文件,控制文件,联机日志,参数文件等);
2) Oracle数据库实例则是一组Oracle后台进程/线程以及在服务器分配的共享内存区。
2.创建表:
语法:
Create table 表名(
字段名1 字段类型 是否为空
字段名2 字段类型 是否为空
)
例子:
Create tabletamp(
Id number(2) not null primarykey,
Tname varchar2 not null
)
3.增加主键
Alter table 表名 add constraint 主键名 primary key (字段1)
4.增加外键
Alter table 表名
add constraint 外键名 foreign key (字段1)
Reference 关联表 (字段2)
5.建立表格时就指定主外键:
create tabletemp(
id number(9) not null
constraint temp_id_pk primary key;
name varchar2(9) not null ;
)
6.查询表:
Select *from 表名
删除表:
Drop table 表名
修改表名:
Rename 表名1 to 表名2;
显示表结构:
Describe 表名
插入:
Insert into 表名 value ()
Commit;
更新;
Update 表名 set 列名=新值 where 列名 = 某值;
7.Sql 中最重要的语句
Create database 创建数据库
Alter database 修改数据库
Create table 创建表
Alter table
Drop table
Create index 创建索引
Drop index
8.Select
select distinct 关键词 DISTINCT 用于返回唯一不同的值。
语法:select distinct 列名 from 表名;
9.Where
select * from 表名 where 列名 运算符 某值
OR 和 AND运算符
Select * from persons where firstname = ‘carter’ andlastname = ‘tomaos’;
Selsct * from persons where firstname = ‘carter’ orlastname = ‘william’;
OR和 AND合并使用
Select * from persons where (firstname = ‘carter’or lastname = ‘william’)
And lastname = ‘tomaos’;
10.ORDER BY 语句用于根据指定的列对结果集进行排序。
ORDER BY 语句默认按照升序对记录进行排序。
如果您希望按照降序对记录进行排序,可以使用 DESC 关键字。