--建表
CREATE TABLE TABLE_NAME1(
DATA_DT VARCHAR(10) NOT NULL,
)IN ODSFTB
INDEX IN ODSFIDX
COMPRESS YES ADAPTIVE;
--更改表格
--表加字段
ALTER TABLE TABLE_NAME1 ADD COLUMN ID VARCHAR(100);
REORG TABLE ODSF.O_BMS_BILL_INFO ;
ALTER TABLE ODSF.O_BMS_BILL_INFO ADD COLUMN SENDDNSIND VARCHAR(1) ;
REORG TABLE ODSF.O_BMS_BILL_INFO ;
COMMIT;
--添加主键
ALTER TABLE TABLE_NAME1
ADD PRIMARY KEY (ID);
ALTER TABLE "ODS"."F_CBS_GLSDAYTOTALW"
ADD PRIMARY KEY
( "BRCCODE", "ACCTYPE", "CCY", "SUBCTRLCODE", "TRANDATE");
COMMIT;
--添加索引
CREATE INDEX INDEX_NAME ON TABLENAME(COLUMN_NAME);
CREATE INDEX ODSF.IND_F_L_PMIS_BUSINESS_HOUSEAPPLY
ON ODSF.F_L_PMIS_BUSINESS_HOUSEAPPLY
(START_DT ASC,END_DT ASC ,APPLYSERIALNO ASC);
--表加字段
ALTER TABLE ODSF.O_BMS_BILL_INFO ADD COLUMN SENDDNSIND VARCHAR(1) ;
REORG TABLE ODSF.O_BMS_BILL_INFO ;
COMMIT;
--变更字段长度
ALTER TABLE ODSF.O_BMS_BILL_INFO ALTER COLUMN AGRMTNB SET DATA TYPE VARCHAR(30);
REORG TABLE ODSF.O_BMS_BILL_INFO ;
COMMIT;
--删除字段
ALTER TABLE ODSF.f_BMS_BILL_INFO drop COLUMN SENDDNSIND CASCADE;COMMIT;
REORG TABLE ODSF.f_BMS_BILL_INFO ;
COMMIT;
--删除表主键
ALTER TABLE ODS.F_CBS_GLSDAYTOTALW DROP PRIMARY KEY ;
REORG TABLE ODSF.f_BMS_BILL_INFO ;
COMMIT;
--新增主键
ALTER TABLE "ODS"."F_CBS_GLSDAYTOTALW"
ADD PRIMARY KEY
( "BRCCODE", "ACCTYPE", "CCY", "SUBCTRLCODE", "TRANDATE");
--新增索引
CREATE INDEX ODSF.IND_F_L_PMIS_BUSINESS_HOUSEAPPLY
ON ODSF.F_L_PMIS_BUSINESS_HOUSEAPPLY
(START_DT ASC,END_DT ASC ,APPLYSERIALNO ASC);
--新增外键
ALTER TABLE tablename ADD CONSTRAINT distfk FOREIGN KEY (address) REFERENCES addresser(address) MATCH FULL
--比如,要想查询book_title中包含字符串'99%'的纪录:
SELECT * FROM BOOKS WHERE BOOK_TITLE LIKE '%99!%%' ESCAPE '!';
--后面的escape '!'是定一个转义字符'!', 指明紧跟着转义字符'!'后的%不再是统配符
--如何获取结果集的前N行数据
SELECT * FROM TABLENAME FETCH FIRST N ROWS ONLY;