DB2
z/OS DB2 LUW z/OS CICS VTAM |
DB2 SQL |
Home |
-- LAST FULL IMAGE Copy
SELECT IC.DBNAME AS
ICDBNAME
,
IC.TSNAME AS ICTSNAME
,
IC.DSNAME AS ICDSNAME
, IC.TIMESTAMP AS
ICTIMESTAMP
,
IC.ICTYPE AS ICTYPE
, IC.FILESEQNO AS
FILESEQNO
FROM SYSIBM.SYSCOPY IC
INNER JOIN SYSIBM.SYSTABLES TB
ON IC.DBNAME = TB.DBNAME
AND IC.TSNAME = TB.TSNAME
AND 'T' = TB.TYPE
WHERE IC.ICTYPE = 'F'
AND IC.ICUNIT = 'T'
AND TIMESTAMP = (SELECT MAX(TIMESTAMP)
FROM SYSIBM.SYSCOPY ICM
WHERE IC.DBNAME = ICM.DBNAME
AND IC.TSNAME = ICM.TSNAME
AND IC.ICTYPE = ICM.ICTYPE
)
AND TB.CREATOR = '<YOURCREATOR>'
GROUP BY IC.DBNAME
, IC.TSNAME
, IC.DSNAME
, IC.TIMESTAMP
, IC.ICTYPE
, IC.FILESEQNO
ORDER BY IC.DBNAME, IC.TSNAME
;
-- SEQUENCES AUF
MAXASSIGNEDVAL VALUE SETZEN
SELECT 'ALTER SEQUENCE '
CONCAT RTRIM(SE.SCHEMA) CONCAT '.' CONCAT RTRIM(SE.NAME)
CONCAT ' RESTART WITH '
CONCAT CASE WHEN SE.MAXASSIGNEDVAL IS NULL THEN
RTRIM(CHAR(BIGINT(SE.START)))
ELSE
RTRIM(CHAR(BIGINT(SE.MAXASSIGNEDVAL + SE.INCREMENT)))
END
CONCAT ' ; '
FROM SYSIBM.SYSSEQUENCES SE
WHERE SE.SEQTYPE = 'S'
AND SE.SCHEMA = 'schema'
-- AND SE.MAXASSIGNEDVAL IS NOT NULL
;
;;
-- IDENTITY COLUMNS AUF MAXASSIGNEDVAL
VALUE SETZEN
SELECT 'ALTER TABLE '
CONCAT RTRIM(SD.DCREATOR) !! '.' !! RTRIM(SD.DNAME)
CONCAT ' ALTER COLUMN ' !! RTRIM(SD. DCOLNAME)
CONCAT ' RESTART WITH '
CONCAT CASE WHEN SE.MAXASSIGNEDVAL IS NULL THEN
RTRIM(CHAR(BIGINT(SE.START)))
ELSE
RTRIM(CHAR(BIGINT(SE.MAXASSIGNEDVAL + SE.INCREMENT)))
END
CONCAT ' ; ' AS ALTER
FROM
SYSIBM.SYSSEQUENCESDEP SD
INNER JOIN
SYSIBM.SYSSEQUENCES SE
ON SD.BSEQUENCEID = SE.SEQUENCEID
WHERE SE.MAXASSIGNEDVAL IS NOT NULL
AND SE.SEQTYPE = 'I'
WHERE SD.DCREATOR = 'TBCreator';
-- ALTER INDEX die mehr als 10
extends haben
SELECT 'ALTER INDEX '
CONCAT RTRIM(CREATOR) CONCAT '.' CONCAT RTRIM(NAME)
CONCAT CASE WHEN PARTITION = 0 THEN ''
ELSE
' PART ' CONCAT RTRIM(CHAR(INT(PARTITION)))
END
CONCAT ' PRIQTY ' CONCAT CHAR(INT(PQTY))
CONCAT ' SECQTY ' CONCAT CHAR(INT(SQTY))
CONCAT ' ;'
FROM (
SELECT SUBSTR(IX.CREATOR, 1, 10) AS CREATOR
, SUBSTR(IX.NAME , 1,
10) AS NAME
, IXS.EXTENTS AS IXS_EXTENTS
, IXS.PARTITION AS PARTITION
, IXP.EXTENTS AS IXP_EXTENTS
, SUBSTR(RTRIM(IX.DBNAME) CONCAT '.'
CONCAT RTRIM(IX.INDEXSPACE)
, 1,
30) AS SPACE
, IXS.SPACE
AS PQTY
, IXP.SPACE / 10 AS SQTY
, IXS.SPACE AS IXSPACE
FROM SYSIBM.SYSINDEXSPACESTATS IXS
INNER JOIN SYSIBM.SYSINDEXES IX
ON IXS.DBID = IX.DBID
AND IXS.ISOBID = IX.ISOBID
AND IXS.ISOBID = IX.ISOBID
INNER JOIN SYSIBM.SYSINDEXPART IXP
ON IX.CREATOR = IXP.IXCREATOR
AND IX.NAME = IXP.IXNAME
AND IXS.PARTITION = IXP.PARTITION
WHERE IXS.EXTENTS > 10
AND IX.CREATOR = 'creator'
) T1
;
-- ALTER TABLESPACE die mehr als
20 extends haben
SELECT 'ALTER TABLESPACE ' CONCAT RTRIM(DBNAME) CONCAT '.'
CONCAT RTRIM(NAME)
CONCAT CASE WHEN PARTITION = 0 THEN ''
ELSE
' PART ' CONCAT RTRIM(CHAR(INT(PARTITION)))
END
CONCAT ' PRIQTY ' CONCAT CHAR(INT(PQTY))
CONCAT ' SECQTY ' CONCAT CHAR(INT(SQTY))
CONCAT ' ; '
FROM (
SELECT
TS.DBNAME
AS DBNAME
,
TS.NAME
AS NAME
,
TSS.PARTITION
AS PARTITION
,
TSS.EXTENTS
AS EXTENTS
,
TSS.SPACE
AS PQTY
, TSS.SPACE /
10
AS SQTY
,
TSS.SPACE
AS SPACE
FROM SYSIBM.SYSTABLESPACESTATS TSS
INNER JOIN SYSIBM.SYSTABLESPACE TS
ON TSS.DBID = TS.DBID
AND TSS.PSID = TS.PSID
INNER JOIN SYSIBM.SYSTABLES TB
ON TS.DBNAME = TB.DBNAME
AND TS.NAME = TB.TSNAME
AND
'T' =
TB.TYPE
INNER JOIN SYSIBM.SYSTABLEPART TP
ON TS.DBNAME = TP.DBNAME
AND TS.NAME = TP.TSNAME
AND TSS.PARTITION = TP.PARTITION
WHERE TSS.EXTENTS > 20
AND TB.CREATOR = 'creator'
) T1
;
WITH TABLENAME (CREATOR, NAME) AS (
SELECT '<YourCreator>', '<YourTBName>%' FROM SYSIBM.SYSDUMMYU
)
, FK_TABLES (LEVEL, PKSCHEMA, PKNAME
, FKSCHEMA, FKNAME) AS (
SELECT 0
, REF.CREATOR
, REF.TBNAME
, REF.REFTBCREATOR
, REF.REFTBNAME
FROM SYSIBM.SYSRELS REF
, TABLENAME TBN
WHERE REF.REFTBCREATOR LIKE TBN.CREATOR
AND REF.REFTBNAME LIKE TBN.NAME
UNION ALL
SELECT P.LEVEL + 1
, R.CREATOR
, R.TBNAME
, R.REFTBCREATOR
, R.REFTBNAME
FROM SYSIBM.SYSRELS R
, FK_TABLES P
WHERE P.LEVEL < 10
AND P.PKSCHEMA = R.REFTBCREATOR
AND P.PKNAME = R.REFTBNAME
)
, SORTTB AS( SELECT *
FROM FK_TABLES
ORDER BY LEVEL, FKSCHEMA, FKNAME )
SELECT DISTINCT
FKSCHEMA, FKNAME
, PKSCHEMA , PKNAME
FROM SORTTB
;