DB: 20 database design best practices
Code
- Use clear and uniform labels and column names, such as school, schoolcourse, and courceid.
- The data table name uses a singular number instead of a plural number, for example, studentcourse, instead of studentcourses.
- Do not use spaces for data table names.
- Do not use unnecessary prefixes or suffixes for data table names, such as using school instead of tblschool or schooltable.
- The password in the database must be encrypted and decrypted in the application. (Hash Storage and one-way encryption)
- Using an integer as the ID field may not be necessary now, but it will be required in the future, such as associated tables and indexes.
- Use integer fields for indexing. Otherwise, it may cause high performance problems.
- Using bit as a Boolean field, using an integer or varcha is a waste. At the same time, such fields should start with "is.
- The database can be accessed only after authentication. do not grant administrator permissions to each user.
- Avoid using "select *" whenever possible, and use "select [required_column_list]" to achieve better performance.
- If the program code is complex, use the ORM framework, such as Hibernate and ibatis. The performance problems of the orm framework can be solved through detailed configuration.
- Separate infrequently used data tables to different physical storage for better performance.
- For key databases, use secure backup systems, such as clusters and synchronization.
- Use foreign keys and non-empty restrictions to ensure data integrity. Do not throw everything to the program.
- The lack of database documentation is fatal. You should design documents for your database, including triggers, stored procedures, and other scripts.
- Indexes are used for frequently used queries and large data tables. Data analysis tools help you decide how to create indexes.
- Database servers and web servers should be placed on different machines. This improves security and reduces CPU pressure.
- Image and BLOB fields should not be defined in common data tables; otherwise, performance will be affected.
- Normalization needs to be used as required to improve performance. Not enough normalization will lead to data redundancy, and excessive normalization will lead to too many joins and data tables, both of which will affect the performance.
- Spend more time on database design. Otherwise, you will pay twice in the future.
. Original link: http://www.javacodegeeks.com/2012/02/20-database-design-best-practices.html