Oracle Database's four major language

First, the data definition language:

1, used to change the database structure, including the creation, change and delete database objects;

2, the command:

create table: creation

alter table modify

drop table drop table

Remove truncate table data table (not rollback)

2, create the table:

 

-- 创建表
create table sclass(
      cid int primary key,
      cname varchar(10)
)

      ssid int primary key, - primary key constraint
 
      sname varchar2 (20) unique, - the only constraint
 
      ssex char (5) check (ssex in ( ' M', 'F')), - check constraints, checks whether the input Male or female
 
      sbirth date not null, - non-empty constraint

      saddress varchar2 (50) default 'Zibo', - the default constraint
     
      --score double check (score between 0 and 100), - the wording range check constraint
     
      CID int,
     
      constraint fk_student_class Foreign Key (CID) References sclass is (CID) - foreign key
)

 

 3, modified table structure:

alter table add / modify / drop (add / modify / delete) Column Name Type name / constraints

4, truncation:

truncate table 表名;

- all the records in the table to delete all but retain the table structure, and do not write the log;

- truncate is DDL language,

  delete from table name is DML language;

5, delete the table: drop

6, data integrity:

= + Accuracy reliability data integrity

Depending on the scope of the database objects and data integrity mechanism of action, data integrity can be divided into the following four types:

①, entity integrity: the only constraint, primary key constraint;

②, domain integrity: data type restrictions, check constraint, default values, not null constraint;

③, referential integrity (referential integrity): foreign key constraints;

④, self-defined integrity: rules, stored procedures

Data integrity constraints:

Create a table: to ensure the integrity of data integrity constraints embodiments =

 

Second, the data manipulation language:

Data Manipulation Language:

  Retrieve, insert, and modify data (by insert, delete delete, change update, search select)

insert into java values ​​(1, 'John Doe', 'M', to_date ( '1997-02-22', 'yyyy-mm-dd'), 'Jinan');

Date Type Use

to_date

 

- copy the table (it does not exist) - just copy the table structure, the table data is not copied (since 1 = 2 is not satisfied)
Create Table Student from Java AS SELECT * WHERE 1 = 2;
     
SELECT * from Student;

- Copy table structure and table of contents, is not bound copy

create table student2 as select * from java;
     
select * from student2;

- Data from the insertion (can be added before select from) other tables

insert into student select * from java;

select * from student;

 

Third, transaction control language:

1, the transaction is the smallest unit of work, work as a whole

2, to ensure the overall success or failure of the transaction, known as transaction control;

3, for transaction control statements are:

commit: commit and terminate the transaction;

rollback: Undo transaction completed work;

savepoint: marked transaction can be rolled back to the point;

Fourth, data control language:

1, the control data provides access control language for the user language;

2, the command:

grant: grant permission;

revoke: revoke permissions have been granted;

 

- Create a user
the Create the User YYM IDENTIFIED by 123456;
Grant Connect, Resource to YYM; - grant permission

- Log administrator account, the user can set permissions to access yym scott.emp table (view only)
Grant the SELECT ON scott.emp to yym with the Option Grant;

select * from scott.emp;

- Undo yym administrator access rights that table just
revoke select on scott.emp from yym;

Guess you like

Origin www.linuxidc.com/Linux/2019-07/159666.htm