DB2 - exemplos simples - ALTER TABLESPACE



Desenvolvido por DORNELLES Carlos Alberto - Analista de Sistemas - Brasília DF. - cad_cobol@hotmail.com

DB2 - exemplos simples - ALTER TABLESPACE

The SQL ALTER TABLE statement is used to add, delete, or modify columns in an existing table.
The ALTER TABLE statement is also used to add and drop various constraints on an existing table.
Following is the table alteration syntax:

A instrução SQL ALTER TABLE é usada para adicionar, excluir ou modificar colunas em uma tabela existente.
A instrução ALTER TABLE também é usada para adicionar e eliminar várias restrições em uma tabela existente.
A seguir está a sintaxe de alteração da tabela:

    ALTER TABLESPACE [database-name.]tablespace-name
          using-block
          free-block
          LOGGED | NOT LOGGED
          TRACKMOD YES/NO
          BUFFERPOOL bp-name
          CCSID ASCII/EBCDIC/UNICODE
          CLOSE YES/NO
          COMPRESS YES/NO
          LOCKMAX integer
          LOCKSIZE ANY/TABLESPACE/TABLE/PAGE/ROW
          MAXROWS integer
          MAXPARTITIONS integer
    using-block:
    USING
          VCAT catalog-name
          STOGROUP stogroup-name
              PRIQTY integer
              SECQTY integer
              ERASE YES/NO
    free-block:
          FREEPAGE integer
          PCTFREE integer

Example 1 - Exemplo 1

Column DEPT_NAME in table DSN8910.TB_DEPARTMENT was created as a VARCHAR(36).
Increase its length to 60 bytes.
Aso, add the column DEPT_BLDG to the table DSN8910.TB_DEPARTMENT.
Describe the new column as a character string column of length is 5.

A coluna DEPT_NAME na tabela DSN8910.TB_DEPARTMENT foi criada como um VARCHAR (36).
Aumente seu comprimento para 60 bytes.
Além disso, inclua a coluna DEPT_BLDG na tabela DSN8910.TB_DEPARTMENT.
Descreva a nova coluna como uma coluna de sequência de caracteres de comprimento 5.

    ALTER TABLE DSN8910.TB_DEPARTMENT
          ALTER COLUMN DEPT_NAME
                SET DATA TYPE VARCHAR(60)
          ADD DEPT_BLDG CHAR(5);

Example 2 - Exemplo 2:

Alter the TB_PRODINFO table to define a foreign key that references a non-primary unique key in the product version table (TB_PRODVER).
The columns of the unique key are PRODVER_NAME and PRODVER_RELNO.

Altere a tabela TB_PRODINFO para definir uma chave estrangeira que faz referência a uma chave exclusiva não primária na tabela de versão do produto (TB_PRODVER).
As colunas da chave exclusiva são PRODVER_NAME e PRODVER_RELNO.

    ALTER TABLE TB_PRODINFO
          FOREIGN KEY (PRODINFO_NAME, PRODINFO_VERNO)
          REFERENCES TB_PRODVER (PRODVER_NAME, PRODVER_RELNO)
          ON DELETE RESTRICT;