home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / sql / create.shr < prev    next >
Text File  |  1988-03-06  |  5KB  |  177 lines

  1.  
  2.  
  3.  
  4.  
  5.          CREATE A TABLE
  6.  
  7.          The create command is used to create a table file.
  8.  
  9.          SYNTAX
  10.          CREATE TABLE table_name (
  11.             column_name  data_type  column_width
  12.            [column_name  data_type  column_width]
  13.          ) number_of_rows;
  14.  
  15.          EXAMPLE:
  16.  
  17.          SSQL> create table cust ( 
  18.              > code char 2   
  19.              > name char 15  
  20.              > st char 2     
  21.              > rating num 2  
  22.              > ) 20;         
  23.  
  24.          The above definition was used to create the cust table used in the 
  25.          documentation.  You can define up to 32 columns in a table.  
  26.          Once a table is created, you can use the insert command to add 
  27.          rows to the table.
  28.  
  29.          table_name
  30.  
  31.          A table name can be from 1 to 8 characters.  The first character 
  32.          must be a letter of the alphabet.  The rest can be letters or 
  33.          digits.  The table file is created on the disk as 
  34.          table_name.SQL.  For example, the cust table, created above would 
  35.          be stored as CUST.SQL on your disk.  However, from SSQL, you would 
  36.          always refer to it as cust.  Since SSQL adds the extension of SQL 
  37.          to all table files, you must not use a period in your table 
  38.          name. 
  39.  
  40.          column_name
  41.  
  42.          A column name can be from 1 to 10 characters.  The first 
  43.          character must be a letter of the alphabet.  The rest can be 
  44.          letters or digits.  In creating column names remember that when 
  45.          a table is displayed, the full column name is displayed too.  
  46.          Long column names tend to fill the screen (or printer) very 
  47.          rapidly when you want to display many columns.
  48.  
  49.          data_type and column_width
  50.  
  51.          NUMBERS 
  52.  
  53.          The data type num is used for numbers.  When you use this data 
  54.          type the values are always right-justified (values are pushed to 
  55.          the right so all the ones column lines up).  Data must be of 
  56.          this type in order to use any of the numeric functions such as 
  57.          avg, max, min, and sum.
  58.  
  59.  
  60.  
  61.  
  62.                                      CREATE-1
  63.          
  64.          
  65.          
  66.          
  67.          
  68.          For the data type num, the column width can be from 1 to 10 
  69.          digits.  Optionally, you can add a decimal indicator for numeric 
  70.          functions.  For Example:
  71.            cost  num  5.2
  72.          This would allow a maximum of 99.99 to be stored in the column 
  73.          if you always used the decimals.  The ONLY time the number of 
  74.          decimal places is checked is when a numeric function takes 
  75.          place, NOT when you are entering data.  If you have a column 
  76.          which stores dollars and cents, remember to always enter the 
  77.          cents even if it is "00".  This would avoid the problem of 
  78.          entering 15 and 23.65 and have the column be displayed as:
  79.               15
  80.            23.65
  81.  
  82.          It is allowable to use whole numbers even though you define it 
  83.          as having decimals.  For example, you want to enter grades 
  84.          which are from  0 to 100 but when you calculate grade averages, 
  85.          you want it calculated to one tenth of a grade point.  You would 
  86.          define the column as:
  87.            grade  num  3.1
  88.  
  89.          You would enter the grades as whole numbers but when the average 
  90.          is calculated, the decimal would be included.  The column width 
  91.          is increased by five when a numeric function is used.  This 
  92.          makes it possible to define something like:
  93.            level  num  2.4
  94.          You could only enter 1-99, but when the average was calculated, 
  95.          it would be to four decimal places.
  96.  
  97.          CHARACTERS
  98.  
  99.          The data type char can be used for any column that is not used 
  100.          in a calculation.  Although the data is usually a combination of 
  101.          alphabetic and numeric data, it is alright if the column just 
  102.          contains digits.  The characters are left-justified.  The 
  103.          maximum column width is 80. 
  104.          
  105.          number_of_rows
  106.  
  107.          The last item you enter is the maximum number of rows that you 
  108.          want in the table.  The minimum number of rows is 11.  If you 
  109.          enter a number less than 11, the table will be created with 11 
  110.          rows.  The maximum number allowable is 32000. 
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.                                       CREATE-2
  118.          
  119.  
  120.  
  121.  
  122.  
  123.  
  124.          DETERMINING HOW A TABLE WAS CREATED (The STRUCT command)
  125.  
  126.          In order to display the create command used to create the table, 
  127.          type:
  128.  
  129.          STRUCT table_name;
  130.  
  131.          where table_name is the name of a table that exists in you 
  132.          database.  For example, to display the table structure for the 
  133.          cust table you would type:
  134.  
  135.          struct cust;
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.          
  175.                                      CREATE-3
  176.          
  177.