Chapter 3 of Mysql Enterprise Employee Study: A's question, company employee

Source: Internet
Author: User

Chapter 3 of Mysql Enterprise Employee Study: A's question, company employee

Chapter 3 question about small A-data type and auto-increment Column

Mr. A took the chicken leg and went back to the room. He bit A bit of oil and said, "I have two questions. In Excell, numbers such as the PetAge column (PET age, I usually set it to a numeric value format, and the default text format for PetName is used. Also, the ID column in Mysql is different from that in Excell. You see, mysql DATA table is a column you write, and Excell is your own. ".

John: "Well, I have to answer your first question. In the Mysql DATA table, there are also data formats, such as PetAge, which we call floating point, that is, the data type with the decimal point. We generally use Double or Float to set the Data Type of this column. For example, PetName is called struct type, we usually use Varchar and Char to set the data type. Of course, the ID column you mentioned is an integer, which is called an integer. We generally use Int to set the data type, the time format is often used. We use DateTime and Date to set the time format. Of course, it's not just these types. There are more types in Mysql, but for beginners like you, you can ignore them temporarily. ".

Small A: "I am confused. I probably know that if the numeric type is an integer, Int type is used. If it is A character, such as Chinese and English, Varchar and Char types are used, if it is time, the DateTime and Date types are used, but this Varchar and Char also have this time. Why are there so many? Which one should I use? ".

Small Y: "In fact, it is very simple. Both Double and Float are used to represent decimal places, but Double supports many digits. in Mysql, 17 digits can be supported, while Float is 6 digits. If you are too troublesome, you can directly use the maximum value Double for unified settings, but if you are a professional database staff, you should decide whether Float or Double based on the data stored in this column. Even if you store the goods, you have opened up 3 square meters of space for the goods. It turns out that the goods are just a mobile phone. Isn't that a waste of space? You opened up a 1-square-meter space, but found that it was a 42-inch TV set, which was even worse. According to Cao, you could not miss the mistake. "

Xiao A: "Xiao Y, I don't know much about books at ordinary times. I am sorry to miss it! That's what Wang Jingwei said! ".

Little Y: "... don't care about details! Besides, Varchar and Char can both store characters, but Varchar can be scaled down freely. That is to say, I opened a 5-square-meter space for mobile phones, but I found that this mobile phone only accounts for 20 cm², so I will leave this location to other items. In other words, Char opened up 5 square meters and put it on a mobile phone, it will not change the storage space. The two have their own advantages. Varchar saves space while Char leads in efficiency. The principle is very simple. Although it is 5 square meters, I put it on a mobile phone, instead, you don't have to worry about narrowing down the location. In terms of life, this will definitely save the time of the Warehouse administrator. "

A: "It seems very reasonable. I just gave it to Varchar. After all, there is A lot of data, which can save A lot of storage space, and the efficiency is not bad. ".

Small Y: "For large data, you need to take a closer look at which data to use. As for DateTime, it is better understood that Datetime represents the year, month, day, hour, minute, and second, and Date can only be written into the year, month, and day. Let's talk about the ID column. As you can see, this column is just a column that tells you the number of rows, but it comes with Excel, and Mysql does not, you need to add the column by yourself. It is useful for this auto-increment column. For example, if I know the sequence number of a column and want to find the information of this column, it will become much easier, therefore, we often need to ensure the uniqueness of this column. We usually set this column as the primary key to ensure the uniqueness of this column, the Key is actually the meaning of the Key. Only this Key can open the door of this line of Data, let's view the data in it, in another sentence, primary keys ensure data integrity. ".

A: "Well... it seems A little hard to understand. ".

John: "Don't worry. Next, we will apply the theoretical knowledge we have learned to practical operations so that you can quickly understand what I have said. ".

A: "Let's get started! ".

John: "It's so late. Hurry up and go to bed. You have to get up early tomorrow! ".

A: "It's so late. I want to ask you for advice tomorrow. ".

Related Article

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.