达梦数据库是一个国产数据库,它的语法和结构类似于oracle,但是又有很多不同,此处记录一下
管理工具在dmdbms下的tool文件夹下
使用tool目录下的manage程序,导出dmp文件,在linux和windows下都可以,但如果没有桌面的服务器,那就只能用命令行了,下面就是命令行导出
./dexp 用户id/密码@ip:5236 file=导出的文件 directory=导出文件所在的目录 导出的模式
导出模式:FULL、OWNER、SCHEMAS、TABLES ;全部导出、根据用户导出、根据模式导出和表导出。
切到tool目录下
./dimp 用户id/密码@ip:5236 file="导入的文件路径(包括文件名)" 导入的模式(一般与库名相同)
导入的时候可能有视图没有的问题,这个就只能手动建立了,一般是在没有达梦官方导入软件可以用的情况下
正常使用管理工具导入导出即可
--------------------统计所有用户表行数
SELECT
T2.NAME AS 模式名,
T1.NAME AS 表名,
TABLE_ROWCOUNT(T2.NAME,T1.NAME) AS 行数
FROM
SYSOBJECTS T1,
SYSOBJECTS T2
WHERE
T1.SCHID = T2.ID
AND T1.SUBTYPE$ = 'UTAB'
AND T2."TYPE$" = 'SCH'
ORDER BY 3 DESC;
--------------------统计所有用户表行数以及筛查某行数级别以上表行数 输入参数1:百万,千万,亿...等等,也可以共存,复制一行
SELECT
模式名,
COUNT(表名) AS 表数量,
COUNT(CASE WHEN 行数 > ? THEN 行数 ELSE NULL END) AS 百万表数量
FROM
(
SELECT
T2.NAME AS 模式名,
T1.NAME AS 表名,
TABLE_ROWCOUNT(T2.NAME,T1.NAME) AS 行数
FROM
SYSOBJECTS T1,
SYSOBJECTS T2
WHERE
T1.SCHID = T2.ID
AND T1.SUBTYPE$ = 'UTAB'
AND T2."TYPE$" = 'SCH'
--ORDER BY 3 DESC
)
GROUP BY 模式名
--------------------获取所有用户表定义
SELECT
T2.NAME AS 模式名,
T1.NAME AS 表名,
T1.CRTDATE AS 创建时间,
DBMS_LOB.SUBSTR(DBMS_METADATA.GET_DDL('TABLE',T1.NAME,T2.NAME)) AS 表定义
FROM
SYSOBJECTS T1,
SYSOBJECTS T2
WHERE
T1."SUBTYPE$" = 'UTAB'
AND T1.SCHID = T2.ID
AND T2."TYPE$" = 'SCH';
--------------------统计用户表列信息
SELECT
S1.NAME AS 表名,
S2.NAME AS 列名,
S2."TYPE$" AS 字段类型,
S2."LENGTH$" AS 字段长度
FROM
SYSOBJECTS S1,
SYSCOLUMNS S2
WHERE
S1."SUBTYPE$" = 'UTAB'
AND S1.ID = S2.ID;
--------------------查看表占用空间大小
SELECT
S2.NAME AS 模式名,
S1.NAME AS 表名,
TABLE_USED_SPACE(S2.NAME,S1.NAME) * PAGE /1024.0/1024.0 AS "表占用空间(MB)"
FROM
SYSOBJECTS S1,
SYSOBJECTS S2
WHERE
S1.SCHID = S2.ID
AND S1."SUBTYPE$" = 'UTAB'
AND S2."TYPE$" = 'SCH'
ORDER BY
3 DESC;
start “sql文件名”
也可以通过在‘||’断开行的方式进行长命令行的切割
-- 查失败次数锁定时间
select
b.username as "达梦数据库用户名",
a.failed_num as "失败次数限制",
a.failed_attemps as "失败尝试次数",
a.lock_time as "锁定时间(min)"
from sysusers a right join all_users b on a.id=b.user_id;
select
username as "达梦数据库用户名",
account_status as "账户状态",
lock_date as "锁定时间"
from dba_users;
alter user NMGJTT_OA account unlock;
之后还会继续使用这个数据库,如果有新的东西会继续更新在这篇文章,或者太多就开个专栏