midrange.com code scratchpad
Name:
Create SQL Table Shell
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
08/23/2012 01:18:58 pm
IP:
Logged
Description:
A shell create table SQL statement
Code:
  1. -- -----------------------------------------------------------------------------
  2. --         Table  . . . :  Table_Name       Author . . :
  3. --         Date . . . . :  mm/dd/yyyy
  4. --         Project  . . :
  5. --         Purpose  . . :
  6. --         Compile Notes:  RUNSQLSTM SRCFILE(library/QSQL) SRCMBR(table_name)
  7. --                         COMMIT(*NONE) ERRLVL(20)
  8. -- -----------------------------------------------------------------------------
  9. --    Modifications:
  10. --
  11. --  Project        Date         Developer                  Description
  12. -- -----------------------------------------------------------------------------
  13. -- xxxxxxxxx    xx/xx/xxxx   xxxxxxxxxxxxxxx   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  14. -- -----------------------------------------------------------------------------
  15.  
  16. -- Drop existing table
  17. -- Drop table &LIB/table_name;
  18.  
  19. -- Create table
  20. Create table &LIB/Format_Name (
  21.   LongName         for shortname       Numeric(19,0) not null,
  22.   Type_Status      for STSTATUS        Char(1) not null with default 'P'
  23.                                          Constraint Table_Name_Record_Status
  24.                                          Check(Type_Status in ('A', 'I', 'P')),
  25.   LongDate         for shortdate       Date,
  26.   LongTimestamp    for shorttimestamp  Timestamp,
  27.   Add_User         for AddUser         Char(18) not null with default USER,
  28.   Add_Timestamp    for AddTmsp         Timestamp not null
  29.                                          with default CURRENT_TIMESTAMP,
  30.   Add_Proc         for AddProc         Char(128) not null,
  31.   Chg_User         for ChgUser         Char(18),
  32.   Chg_Timestamp    for ChgTmsp         Timestamp,
  33.   Chg_Proc         for ChgProc         Char(128),
  34.   Dlt_User         for DltUser         Char(18),
  35.   Dlt_Timestamp    for DltTmsp         Timestamp,
  36.   Dlt_Proc         for DltProc         Char(128),
  37.  
  38.   -- Create primary key(s)
  39.   Constraint Table_Name_Key Primary Key (Primary_Key_1, Primary_Key_2),
  40.  
  41.   -- Referential constraint
  42.   Constraint Valid_Table_Name_Field
  43.     Foreign key (Table_Field_1, Table_Field_2)
  44.       references Ref_Table (Ref_Field_1, Ref_Field_2)
  45.     On delete cascade
  46.     On update RESTRICT);
  47.  
  48. -- Assign long name and system name
  49. Rename Format_Name to Long_Table_Name for system name Table_Name;
  50.  
  51. -- Add text description to the file
  52. Label on table table_Name
  53.   is 'Table description goes here---------------------->';
  54.  
  55. -- Add column headings to the fields
  56. Label on column table_name (
  57.   longname              is 'Heading 1---------->Heading 2---------->Heading 3---------->');
  58.   Add_User              is 'Add User',
  59.   Add_Timestamp         is 'Add Timestamp',
  60.   Add_Proc              is 'Add Procedure',
  61.   Chg_User              is 'Change User',
  62.   Chg_Timestamp         is 'Change Timestamp',
  63.   Chg_Proc              is 'Change Procedure',
  64.   Dlt_User              is 'Delete User',
  65.   Dlt_Timestamp         is 'Delete Timestamp',
  66.   Dlt_Proc              is 'Delete Procedure');
  67.  
  68. -- Add column text to the fields
  69. Label on column table_name (
  70.   longname              text is 'Description-------------------------------------->');
  71.   Add_User              text is 'Add user',
  72.   Add_Timestamp         text is 'Add timestamp',
  73.   Add_Proc              text is 'Add procedure',
  74.   Chg_User              text is 'Change user',
  75.   Chg_Timestamp         text is 'Change timestamp',
  76.   Chg_Proc              text is 'Change procedure',
  77.   Dlt_User              text is 'Delete user',
  78.   Dlt_Timestamp         text is 'Delete timestamp',
  79.   Dlt_Proc              text is 'Delete procedure'); 
© 2004-2019 by midrange.com generated in 0.006s valid xhtml & css