Database and table guidelines

When you are working with database tables, keep in mind the following guidelines:

  • Pick the right data type or pick the right size. For example:
    • Use date (4 bytes) rather than datetime (8 bytes).
    • Use int1 (1 byte) or INT2 (2 bytes) rather than integer (4 bytes).
  • Use the same data type and size for columns that you join against.
  • Specify NOT NULL for columns, whenever possible.
    • NOT NULL requires less processing/instructions.
    • NOT NULL requires (slightly) less storage.
  • Select a good distribution key, as described in Distribution keys.
  • If necessary, specify organizing keys to improve queries on large fact tables, as described in Clustered base tables.
  • Periodically generate statistics for the tables. See Database statistics.