Management database up to the dream

Manage tables, views, indexes, sequences

Management table

Which express support for the Dream:
The default table is (index-organized tables), heap table, temporary table, partition table, external table and so on.

How to plan the table?

Name: begin with a letter az, 0-9, $ # _
data type: int char varchar date clob blob number, and so on.
Storage location: Table space their own planning.
Constraint (constraint five)
non-null constraints, unique constraints, primary keys, checks, foreign key
Note: comment
followed Paradigm 3

Case 1: Planning a student information form.

表名:STU
学号(id char(10)), 
姓名(sname varchar(20) not null),
性别 (sex char(1))
年龄(age int)
电话(tel varchar(15) not null)
家庭住址:(address varchar(50))
表空间:STU
约束:主键列---学号   非空---姓名,电话
备注:学员信息表

create table "TEST3"."STU"
(
    "ID" CHAR(10) not null ,
    "SNAME" VARCHAR(20) not null ,
    "SEX" CHAR(1),
    "AGE" INT,
    "TEL" VARCHAR(15) not null ,
    "ADDRESS" VARCHAR(50),
    primary key("ID")
)
storage(initial 1, next 1, minextents 1, fillfactor 0, on "STU");
comment on table "TEST3"."STU" is '学员信息表';
comment on column "TEST3"."STU"."ID" is '学号';
comment on column "TEST3"."STU"."SNAME" is '姓名';
comment on column "TEST3"."STU"."SEX" is '性别';
comment on column "TEST3"."STU"."AGE" is '年龄';
comment on column "TEST3"."STU"."TEL" is '电话';
comment on column "TEST3"."STU"."ADDRESS" is '家庭住址';

How to view the table structure

sp_tabledef ( 'TEST3', 'the STU');
SELECT DBMS_METADATA.GET_DDL ( 'TABLE', 'the STU', 'TEST3');
How to view the table belongs tablespace
select table_name, tablespace_name from dba_tables where table_name = 'STU';
How see table What constraints
select table_name, constraint_name, constraint_type from dba_constraints where table_name = 'STU';
case 2: when you create a table of specified constraints
the create the table test3.t2 (the above mentioned id int);
Alert the table test3.t2 the Modify the above mentioned id int not null;
create table test3.t3 (id int not null );
unique constraints
create table test3.t4 (id int unique) ;
primary key constraint
create tabel test3.t5 (id int primary key );
check constraint
create table test3.t6 (id int check (ID> =. 5));
Create Table test3.t7 (int ID);
alter table test3.t7 add constraint t7_check check(id>=5);
外键约束
create table test3.t9(sid int primary key,pid int);
create table test3.t10(id int primary key ,sid int foreign key references test3.t9(sid));

Table Notes

Case 3: Add notes
comment on column test3.t2.id is 'No';

How to import data into the table

Case 4: How to import data into the table.
start /home/dmdba/a.sql
do migrate through the DTS tool
DaMeng installation directory Tool
./dts

How to maintain the table:

Rename the
alter table test3.t2 rename tt;
increase to delete the column
to increase the column
alter table test3.tt add name varchar (10 ) default 'aa';
remove columns
alter table test3.tt drop name;
enable and disable constraints
(when migrating data it is best to disable the constraint, then the migration is complete enabled)
the ALTER the table test3.t6 disable constraint A CONS134218780;
the ALTER the table test3.t6 enable constraint A CONS134218780;
drop table
drop table test3.tt;

view

Simple view and complex view, materialized view
Note: Simple view and complex view does not occupy disk space
materialized view will take up disk space

Creating syntax:

Create view () as select () from () where ();

View View

select view_name,text from dba_views where view_name='V1';

Modify View

create or replace view test3.v1 as select employee_name,job_id from dmhr.employee;

Delete View

drop view v1;

sequence

Creating a Sequence

Sequence test3.s1 Create
2 Start with a starting sequence number. 1 ----
3 increment by 1 - increment number
4 maxvalue 5 --- maximum
5 nocache --- whether the buffer
6 nocycle; --- if the loop

Application sequence

insert into test3.t12 values(s1.nextval);

Synonyms

Alias ​​tables or views, synonyms divided into ordinary, common synonyms

Create synonyms:

公共:SQL> create public synonym ss1 for dmhr.employee;
普通:SQL> create synonym ss2 for dmhr.employee;

Modify Synonyms:

create or replace synonym ss2 for dmhr.city;

Delete Synonym:

drop synonym ss2;
drop public synonym ss1;

index

Support Index DaMeng that:
the secondary index, a bitmap index, a unique index, a composite index, index function, partition index and the like.
The default table is an index-organized table, use rowid create a default, indexes we created, called secondary index.

View index table

select table_name,index_name from dba_indexes where table_name='T12';

The role of the index

Accelerate the lookup table, to do database DML operations, the database will automatically maintain the index. The index is an inverted tree, use an index is to do tree traversal of the index tree.

Establish rules index

1: column regular query
2, the connection condition column
3, column (WHERE) predicate recurrent
4, the query is to return the table a small amount of data
without suitable index:
1, with a column a large number of null
columns on limited data (e.g., gender)

How to create an index

1, the index table space planning
2, the data table is disordered, the index data is ordered.

Emp in employee_id index.

Creating tables:
the SQL> Create AS SELECT * from Table test3.emp dmhr.employee;
indexed table space
SQL> create tablespace index1 datafile '/dm7/data/DAMENG/index01.dbf ' size 32;
index:
the SQL> Create index ind_emp on test3.emp (employee_id) tablespace index1 ;
query index:
SELECT table_name, index_name from table_name = DBA_INDEXES WHERE 'the EMP';

View the execution schedule:


Do not take the index, statistics are old, need to collect

re-collect, take the index up.

Note, create an index, delete, rebuild the index and gather statistics, do not do it during peak.

Maintenance Index:

重建:alter index test3.IND_EMP rebuild;
删除:drop index test3.ind_emp;

十一、备份还原

备份作用?
1、防止误操作
2、软件硬件故障
3、防止天灾人祸
备份方式:物理备份,逻辑备份
1、物理备份还原:
冷备:(dmap服务打开的状态下,数据库是关闭的)
热备:(dmap服务一定是打开的,数据库也是打开的,数据库要开归档)
导入导出:dexp dimp
集群:数据守护(dw),dsc(rac)
达梦支持第三方的备份软件:爱数,鼎甲。

数据库开归档:

命令方式下:

SQL> alter database mount;
SQL> alter database add archivelog 'type=local,dest=/dm7/arch,file_size=64,space_limit=0';
SQL> alter database archivelog;
SQL> alter database open;

SQL> select name,status$,arch_mode from v$database;
利用管理工具开归档:
tool/manager

通过dmrman去备份

Dmap服务要开启,数据库实例关闭。

命令行方式下全备,增量备

mkdir /dm7/backup
SQL> backup database full backupset '/dm7/backup/full_bak';
SQL> select checkpoint(0);
SQL> backup database increment backupset '/dm7/backup/incr_bak';

利用管理工具进行热备

还原

模拟表空间破坏 tbs2

mv tbs2_01.dbf tbs2_01.dbf.bak
重启服务,数据库处于mount 状态。手动open;
SQL> alter database open;
restore tablespace tbs2 from backupset '/dm7/backup/full_bak/';
SQL> alter tablespace tbs2 online;

逻辑导入导出

Dexp 逻辑导出 dimp 逻辑导入
Dexp和dimp是DM自带的工具,分为四种级别:
数据库级,用户级、模式级和表级。四种级别独立互斥,不能同时存在。四种级别所提供的功能:
数据库级(full):导出或导入整个数据库中的访问对象。
用户级(owner):导出或导入一个或多个用户所拥有的所有对象。
模式级(schemas):导出或导入一个或多个模式下的所有对象。
表级(table):导出或导入一个或多个指定的表或表分区。

[dmdba@dca01 bin]$ disql sysdba/SYSDBA@localhost:5237
SQL> create user DMHR identified by dameng123;
SQL> create user TEST2 identified by dameng123;
SQL> create user TEST3 identified by dameng123;
[dmdba@dca01 bin]$ ./dimp sysdba/SYSDBA@localhost:5237 file=/dm7/backup/dexp/dexp01.dmp log=dimp02.log directory=/dm7/data/dimp/

配置ODBC

1、LINUX环境中配置ODBC环境

[root@dca01 installdoc]# tar -xzvf unixODBC-2.3.0.tar.gz 
[root@dca01 installdoc]# cd unixODBC-2.3.0
[root@dca01 unixODBC-2.3.0]# ./configure --enable-gui=no
[root@dca01 unixODBC-2.3.0]# make
[root@dca01 unixODBC-2.3.0]# make install
[root@dca01 unixODBC-2.3.0]# odbc_config --version
2.3.0
[root@dca01 unixODBC-2.3.0]# odbc_config --odbcini
/usr/local/etc/odbc.ini


修改配置文件

Odbc.ini
[dm7]
Desription=DM ODBC DSND
Driver = DM7 ODBC DRIVER
SERVER = localhost
UID = SYSDBA
PWD = dameng123
TCP_PORT = 5236
配置odbcinst.ini
[DM7 ODBC DRIVER]
Description = ODBC DRIVER FOR DM7
Driver = /dm7/bin/libdodbc.so
[root@dca01 etc]# chmod 775 odbc.ini 
[root@dca01 etc]# chmod 775 odbcinst.ini 

测试连接

Guess you like

Origin www.cnblogs.com/zililove/p/11962318.html