[达梦]达梦数据库的日常操作
一、检查数据库表是否存在
select * from all_Objects where owner ='TEST' and object_type='TABLE' and Object_name like '%HC%';
二、查看建表语句
select DBMS_METADATA.GET_DDL('TABLE','数据库表') from dual;
三、新增字段
alter table "user" add column("is_del" CHAR(1));
comment on column "user" ."is_del" is '删除标志,1是0否';
四、重命名字段名称
alter table "user" rename column "name" to "user_name";
五、修改字段
-- 设置字段默认值
ALTER TABLE "USER" MODIFY "CREATER_ID" NULL;
-- 修改字段长度
ALTER TABLE "USER" MODIFY USER_NAME VARCHAR(150);
-- 修改字段类型(慎用)
alter table "USER" modify DFQZ int;
六、索引
-- 创建普通索引
CREATE INDEX idx_user_name ON employee(USER_NAME);
SELECT table_name, index_name, index_type
from user_indexes WHERE index_name='idx_user_name';
-- 删除索引
DROP INDEX idx_user_name;
七、表字段查看
select * from all_tab_columns where owner='TEST' and Table_Name='USER';
select * from dba_col_comments where owner='TEST' and Table_Name='USER';
好学若饥,谦卑若愚