Dream up a database commonly used statement paradigm by Crystane Dec 27,2019

1. Create a table space
- creating initial size of 32M tablespace;
Create Test TABLESPACE datafile '/dm7/data/DAMENG/TEST1_01.DBF' SIZE 32;
- 50M creating initial size of table space, automatic extension, the maximum expanded to 100M;
Create tABLESPACE TBS1 datafile '/dm7/data/DAMENG/tbs1_02.dbf' ON MAXSIZE size AUTOEXTEND 50 100;
- creating initial size of table space 50M, automatic extension, the maximum extension to 100M, 1M increments ;
Create tABLESPACE tbs3 datafile '/dm7/data/DAMENG/tbs3_02.dbf' Next size 50 AUTOEXTEND ON MAXSIZE. 1 100;
2. Display space
SELECT * from DBA_TABLESPACES;
SYSTEM: system data and global data dictionary.
ROLL: storing the rollback process database records generated by the operation.
UNDO_RETENTION: in seconds
TEMP: temporary table space
MAIN: the default database table space, create a data object, if you do not specify a storage location, stored in the default table space.
HMAIN: HUGE space table
3. Table space increased documents
- can be associated with a plurality of table space tablespace files;
TBS2 the Add datafile TABLESPACE ALTER 'Dm7 / Data / DAMNENG / tbs2_02.dbf' ON MAXSIZE size AUTOEXTEND 50 100;
4. Replace the memory location of the table space or replace file name
- First tablespace offline;
ALTER TABLESPACE tbs4 Offline;
- spatial change table storage location or replacement tablespace name;
ALTER tABLESPACE tbs4 the rename datafile '/dm7/data/DAMENG/tbs4_02.dbf' to '/dm7/data/tbs4_02.dbf';
- after the modification is completed on-line table space;

Online tbs4 TABLESPACE ALTER;
5. The drop tablespaces

drop tablespace tbs1;

6. Create a user
--identifiled by designated identification code
--limit password_life_time Specifies the maximum survival time (days)
--failed_login_attemps specify the maximum number of failed login
--password_lock_time specified lock time (minutes);

User test1 IDENTIFIED by dameng123 Create PASSWORD_LIFE_TIME limit 60, failed_login_attemps 2, PASSWORD_LOCK_TIME. 5;
7. The current user view
SELECT User;
8. The Field Comment
COMMENT ON column TEST1.STU.ADDRESS IS 'participants address';
9. view all user
SELECT from DBA_USERS;
SELECT
from the all_users;

10.创建表
--CREATE TABLE SALESORDER_DETAIL EXAMPLE
CREATE TABLE SALES.SALESORDER_DETAIL
(SALESORDERID INT NOT NULL REFERENCES
SALES.SALESORDER_HEADER(SALESORDERID),
SALESORDER_DETAILID INT NOT NULL,
CARRIERNO VARCHAR(25) NOT NULL,
PRODUCTID INT NOT NULL REFERENCES PRODUCTION.PRODUCT(PRODUCTID),
ORDERQTY INT NOT NULL,
LINETOTAL DEC(19,4) NOT NULL,
PRIMARY KEY(SALESORDERID,SALESORDER_DETAILID)) STORAGE (ON BOOKSHOP);
11.插入数据
--INSERT ADDRESS EXAMPLE
INSERT INTO PERSON.ADDRESS(ADDRESS1,ADDRESS2,CITY,POSTALCODE) VALUES('洪山
区 369 号金地太阳城 56-1-202','','武汉市洪山区','430073');

12. Review the table table space, an owner and other information;
the SELECT * from dba_tables the WHERE table_name = 'STU';
dba_tables see the Administrator's Guide ORACLE table structure compatible with the view section 13;
Table 13. Structure Query created;
the SELECT DBMS_METADATA.GET_DDL ( 'TABLE', 'STU', 'TEST2');
or
sp_tabledef ( 'TEST', 'STU ');

14. rename table
ALTER Table test1.STU the rename to the STUDENT;
15. A add or delete columns
ALTER Table test1.student the Add SFID VARCHAR (18 is);
ALTER Table test1.student drop SFID;
16. A Note to Table
COMMENT ON TABLE "TEST1" . "the STU" the iS 'Xue Yuan';
17. a drop table
drop table test1.student;
18. a view roles the user;

the SELECT from dba_role_privs the WHERE GRANTEE = 'the Test';
permission to 19. query role of
the SELECT
from dba_sys_privs the WHERE GRANTEE = 'the PUBLIC';

20. The rights granted and recover

grant select on test.test_table to test1;
grant select(city_id,city_name) on dmhr.city to test;

REVOKE grant select on test.test_table to test1;

21. Check constraint information table;
the SELECT * from DBA_CONSTRAINTS the WHERE table_name = 'TEST3';
DBA_CONSTRAINTS see the Administrator's Guide ORACLE table structure compatible with the view section 12;
22. Create Constraint
- a check constraint
create table test2.t8 (id int check ( ID> =. 5));
- the only constraint
Create Table test2.T3 (uNIQUE ID int);
- primary key constraint
Create Table test2.T5 (int primary key ID);
- foreign key constraint
create table test2.t10 (sid Primary Key int, int PID);
Create Table test2.t11 (int Primary Key ID, SID Foreign Key References test2.t10 int (SID));

23. disable, enable constraints
ALTER Table test.TEST3 disable constraint CONS134218845;
ALTER Table test.TEST3 enable constraint CONS134218845;

24. Create, or update, modify, view
Create View dmhr.employee_column_controlled AS
SELECT Employee_name, the salary from dmhr.employee;

View dmhr.employee_column_controll or the replace the Create
AS the SELECT Employee_name, salary from dmhr.employee;
25. The auto-increment;
create
create sequence test.s1 --- test as a model name
start with 1 --- initiation sequence
increment by 1 - - how much increment
maxvalue 5 --- maximum
nocache ---- whether the cache
nocycle; --- whether loop
applications:
the Create the Table test.t12 (the above mentioned id int Primary Key);
INSERT INTO test.t12 values (test.s1 .nextval);
SELECT test.s1.nextval;
INSERT INTO test.t12 values (test.s1.nextval);
INSERT INTO test.t12 values (test.s1.nextval);
INSERT INTO test.t12 values (test.s1. nextval);
the SELECT test.s1.nextval; - this statement fails, the sequence of overflow. Data tables are also used data query sequence 1,3,4,5 out.
Modifications
alter sequence test.s1 maxvalue 10;
Query
select * from dba_sequences where sequence_name = ' S1';
delete
drop Sequence test.s1;
26. The synonyms
global synonyms
create public synonym SY1 for dmhr.employee;

SELECT * from dba_synonyms;

select * from dba_synonyms where SYNONYM_NAME = 'SY1';

drop public synonym SY1;
local synonym

create synonym SY1 for dmhr.employee;

SELECT * from dba_synonyms;

select * from dba_synonyms where SYNONYM_NAME = 'SY1';

drop synonym SY1;

27.索引
select from dba_indexes;
select
from dba_indexes where table_name = 'CITY';
create table test.emp as select * from dmhr.employee;
create tablespace index1 datafile '/dm7/data/DAMENG/index01.dbf' size 32;
create index ind_emp on test.emp(employee_id) tablespace index1;
select table_name,index_name from dba_indexes where table_name='EMP';

EXPLAIN SELECT * FROM TEST.EMP WHERE EMPLOYEE_ID < 20;
sp_create_system_packages(1);
begin
dbms_stats.gather_table_stats('TEST','EMP');
end;

test.ind_emp the rebuild index ALTER;
ALTER index test.ind_emp the rebuild Online;
drop index test.ind_emp;
28. A archiving settings
SELECT * from V $ Database;
--ARCH_MODE = N indicates that no open archives, Y represents turned archived
alter database mount ;
ALTER ARCHIVELOG the Add Database 'type = local, dest = / Dm7 / Arch, FILE_SIZE = 64, SPACE_LIMIT = 0';
ALTER Database ARCHIVELOG;
ALTER Open Database;
29. A backup and restore
- full backup
backup database full backupset '/ dm7 / backup / Full ';
SELECT the checkpoint (0);
- incremental backup
--with backupdir yl specified directory
backup Database with the backupdir iNCREMENT' / Dm7 / backup / Full 'BACKUPSET' / Dm7 / backup / incr ';
- table space reduction
restore tablespace tbs2 from backupset '/ dm7 / backup / full';

- logical backup
./dexp SYSDBA / the SYSDBA @ localhost: 5236 File Directory dexp01.log = = = log dexp01.dmp / Dm7 / Backup / Dexp Full = Y
- logical restore

./dimp sysdba/SYSDBA@localhost:5236 file=/dm7/backup/dexp/dexp01.dmp log=dimp02.log directory=/dm7/backup/dexp

  1. Job management
    --SYSJOBS: job information
    the SELECT from SYSJOB.SYSJOBS;
    --SYSJOBSCHEDULES: job scheduling information
    the SELECT
    from SYSJOB.SYSJOBSCHEDULES;
    --SYSJOBHISTORIES: job history information
    select * from SYSJOB.SYSJOBHISTORIES;

Guess you like

Origin blog.51cto.com/8760739/2462571