Oracle11G-SQL开发指南-1-简介

1.1 关系数据库简介
    关系数据库:relational database
    表:table
    行:row
    列:column
    模式:schema
    数据库管理系统DBMS: Database Managegment System
    结构化查询语言SQL: Structured Query Language


1.2 结构化查询语言(SQL)简介
    由美国国家标准化组织ANSI: American National Standards Institute
    SQL可以分成五类:
        1> 查询语句,用于检索数据库表中存储的行 
   SELECT(查询行数据)


2> 数据操纵语言DML: Data Manipulation Language 用于修改表的内容
            INSERT(添加行数据)、UPDATE(修改行数据)、DELETE(删除行数据)


        3> 数据定义语言DDL: Data Definition Language 用于定义数据库的数据结构,
            CREATE(创建)、ALTER(修改)、DROP(删除)、RENAME(重命名)、TRUNCATE(清空表)


4> 事务控制语句TC:Transaction Control 用于将对行所做的修改永久性的存储到表中,或取消修改操作
            COMMMIT(提交保存)、ROLLBACK(回滚撤销)、SAVEPOINT(保存点)


5> 数据控制语言DCL: Data Control Language 用于修改数据结构的操作权限
   GRANT(授权)、 REVOKE(撤权)


1.3 使用SQL*Plus
    1> 使用菜单工具
    2> 使用命令行 sqlplus [user_name[/password[@ host_string]]]


1.4 图形工具 SQL Developer


1.5 创建store模式
    SQL语句在"oracle database 11g sql开发指南\sql_book\SQL\store_schema.sql"
    
    1> 创建用户,初始化密码
    2> 授于用户相应权限
    3> 了解Oracle常用的数据类型char(length)、varchar2(length)、date、integer、number(precision, scale)、binary_float、binary_double
    4> constraint约束[primary key(主键)|foreign key(外键)|not null(非空)|unique(唯一)|check(检查)]
    5> references参考


1.6 添加(insert into )、修改(update ... set )、删除行(delete from ...)


1.7 binary_float: 存储单精度32位浮点数
    binary_double 存储双数度64位浮点数
    
    create table binary_test (bin_float binary_float, bin_double binary_double);
    insert into binary_test (bin_float,bin_double) values (39.5f, 15.7d);


1.8 退出sqlplus
    >exit


其它说明:
第一种形式:
CREATE TABLE purchases (
  product_id INTEGER  CONSTRAINT purchases_fk_products  REFERENCES products(product_id),
  customer_id INTEGER CONSTRAINT purchases_fk_customers REFERENCES customers(customer_id),
  quantity INTEGER NOT NULL,
  CONSTRAINT purchases_pk PRIMARY KEY (product_id, customer_id)
);


第二种形式:
-- Create table
create table PURCHASES(
  product_id  INTEGER not null,
  customer_id INTEGER not null,
  quantity    INTEGER not null
);
-- Create/Recreate primary, unique and foreign key constraints 
alter table PURCHASES add constraint PURCHASES_PK primary key (PRODUCT_ID, CUSTOMER_ID);
alter table PURCHASES add constraint PURCHASES_FK_CUSTOMERS foreign key (CUSTOMER_ID) references CUSTOMERS (CUSTOMER_ID);
alter table PURCHASES add constraint PURCHASES_FK_PRODUCTS foreign key (PRODUCT_ID) references PRODUCTS (PRODUCT_ID);





























































你可能感兴趣的:(oracle,sql)