Tables and indexes
- Always use a column list in INSERT statements of SQL queries. This will avoid a problem when table structure changes.
Correct : INSERT INTO tmp (Value) SELECT @variable
- INSERT INTO tmp (Value) VALUES(@variable)
- Not correct : INSERT INTO tmp SELECT @variable
- INSERT INTO tmp VALUES(@variable)
- Perform all referential integrity checks and data validations using constraints instead of triggers, as they are faster.
- Remember to add foreign-key constraints where a table references another.
- Always check with the Database Administrator to confirm what indexes should be added when a new table is added to the database.