表常用操作

2022-05-08 12:51:13 字數 967 閱讀 8217

一、db2

1、備份

--複製要備份的表的結構(索引沒辦法複製)

create table 新表表名 like 要備份的表名;

--寫入資料

insert into 新表表名 select * from 要備份的表名;

2、增、刪、改欄位column

--

增加欄位並注釋

alter

table 表名 add

column 字段 varchar(64

);comment

oncolumn 表名.欄位 is'注釋

';--刪除字段

alter

table 表名 drop

column

字段;--

變更'建設規格'字串長度(只能變大不能變小)

alter

table 表名 alter

column 字段 set data type varchar(32

);--

設定非空約束

alter

table 表名 alter

column 字段 set

notnull;--

刪除非空約束

alter

table 表名 alter

column 字段 drop

notnull;--

重組call sysproc.admin_cmd('

reorg table 表名

');

注意:1)不允許修改欄位名稱(只能先刪除,在新增)

2)不允許減小字段長度(只能加大)

3)不允許修改字段型別(如數值型別改varchar)

二、oracle

--建表同時備份資料

create table 新表表名 as select * from 備份的表名;

三、刪表

drop table 表名;

Sql 常用表操作

1 建立表 create tabletable name field name data type not null null primary key 若仿照另乙個表來新建該錶用 create table as create table table name1 as select coumn1,co...

常用Hive表操作

一 hive建表語句 create table if not exists test id int,name string,age int 預設底層儲存為文字檔案,且為預設分隔符 create table if not exists test id int,name string,age int r...

Sybase常用表操作

sybase常用表操作 表建立 建立一名為 rds custom ftp 的表,並設定id gap為1000.create table rds custom ftp sid numeric 12,0 identity,sub no int not null,ftp url varchar 50 no...