Database Design-Time recommendations

Source: Internet
Author: User

1. When the database is designed, if it is a drop-down box that represents the state of the box, do not hardcode these status values in the code, because these are likely to change with the late demand changes, it is recommended to use a digital representation, the advantage is

A. If the status string changes, but the value can be the same, so that if other modules depend on the value, it will not affect them

B. If you maintain these values with the database table classes later, the advantages of the numbers are reflected and can be directly compatible. (It's also important to design it as a tinyint, so there's no such problem.)

char and varchar in 2.mysql

A book written in China says Char will automatically remove the extra space, and varchar will not.

Server version:5.5.49-0ubuntu0.14.04.1 (Ubuntu)

Today I did a test result that I was very silent ah, inserted a long string (more than 255), and then perform the insert operation, and then he succeeded, but he put more than the character cut off. This is probably related to the version and operating system, the previous time on Windows, the database will report this character too long error,

So I think it is necessary to do the length check in the background code.

query tables are associated with those tables (when you want to delete a table, you are prompted that the table is associated with another table, and if you are interested in knowing which tables are associated, Source: http://zhidao.baidu.com/question/198072067)

Select Table_name,column_name,constraint_name,
Referenced_table_name,referenced_column_name from key_column_usage where referenced_table_name = ' <table> ';

If you need to see the foreign key relationships on a column, you need to add a column condition Referenced_column_name.xx=xx

Show create table name; This command can view all information about a table, including some field types, field constraints, foreign keys, primary keys, indexes, character encodings, and so on.

 

Mysql> Insert  intoBook (NAME) value ('1121212121212121212122222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 2222222222222222222222222222222222222222222222222222222222222222222222333333333333333333333333333333333333333333333333333 3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333 3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333 3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333 33333333333333333333333333333333333333333333333333333333333333333333322222222222222222223wreeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee Eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeewwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww Wwwwwwwwwwwwwwwwwwwweeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeesssssssssssssssssssss Sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss Sssssssssssssssffffffffffffsfdfsddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd Ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd Ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd dddddddddddd22222222222222222222222222222222222222222222'); Query OK,1Row affected,1Warning (0.07sec) MySQL> Select *  fromBook ;+----+-------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- ------------------------------------------+--------+-------+----------+---------------------+--------+|Id|NAME|AUTHOR|Price|INFO|Publishdate|Amount|+----+-------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- ------------------------------------------+--------+-------+----------+---------------------+--------+|  1 |Java|Sun123| 100.9 |Java EE|  -- One- - xx:xx:xx |      0 ||  2 | 123                                                                                                                                                                                                                                                             |Qq|   123 |Testtest|  -- A- A  A: A: A |      0 ||  3 |Ooop|Kkk|  1212 |1212asdf|  -- A- A  A: Geneva: A |    233 ||  4 |Qwe| 123    |   123 |Qwewertr| NULL                |    123 ||  5 | 11212121212121212121222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 222222222222222222 | NULL   |  NULL | NULL     | NULL                |      0 |+----+-------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- ------------------------------------------+--------+-------+----------+---------------------+--------+5Rowsinch Set(0.00Sec

Database Design-Time recommendations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.