Website Development Prices

Search Blog

Wednesday, December 16, 2015

Biranje tipova za kolone (Choosing the types of columns)

Kad jednom odredite tabele i kolone potrebne u bazi podataka, trebalo bi da odredite tip podatka za svaku kolonu. Kada pravite tabelu, MySQL zahteva da se za svaku kolonu eksplicitno navede koju vrstu informacija ce da sadrzi. Postoje tri osnovna tipa:

  • tekst (srting)
  • brojevi
  • datum i vreme 
Pravilno biranje tipova  za kolone odredjuje koje informacije ce moci da se cuvaju i na koji nacin. Takodje, pravilno biranje tipova utice na sveukupne performanse baze podataka. 

Mnogi tipovi prihvataju neobavezan atribut Length. koji ogranicava duzinu. Uglaste zagrade [] oznacavaju da je parametar neobavezan i da se stavlja u zagradu. Za bolje performanse baze podataka, trebalo bi da postavite neka ogranicenja na kolicinu podataka.

Napomena: ako pokusate da ubacite string duzine od pet znakova u kolonu CHAR(2), zadnja tri znaka ce biti odsecena. Sacuvala bi se samo prva dva znaka, ostatak bi bio zauvek izgubljen. To vazi za svako polje  kojem je fiksirana duzina (CHAR, VARCHAR, INT, itd.).

Postoje i dva specijalna tipa - ENUM i SET. Oni omogucavaju da definiete niz prihvatljivih vrednosti za tu kolonu. U koloni tipa ENUM mozete da sacuvate samo jednu vrednost od mogucih nekoliko hiljada. Za kolonu tipa SET dozvoljeno je nekoliko od najvise 64 moguce vrednosti. One su dostupne u MySQL-u ali ne postoje u svakoj aplikaciji baze podataka.




U sledecem clanku pogledajte tabelu sa tipovima podataka u MySQL-u.


Once you specify the tables and columns required in the database, you should specify a data type for each column. When you create a table, MySQL requires that you for each column explicitly specify what kind of information would contain. There are three basic types:
  • text (string)
  • numbers
  • date and time
Proper choice of types of columns determines which information will be able to be preserved and how. Also, the proper choice of types of columns affects overall performance of the database.

Many types accept optional attribute Length. which limits the length. Square brackets [] indicate that the parameter is optional and may be placed in brackets. For better database performance, you should put some limitations on the amount of data.

Note: If you try to insert the string length of five characters in a column CHAR(2), the last three characters will be cut off. It would save only the first two characters, the rest would be lost forever. It is valid for each field which is fixed length (CHAR, VARCHAR, INT, etc.).

There are two special types - ENUM and SET. They make it possible to specify a series of acceptable values ​​for that column. With column type ENUM you can save only one value of the possible several thousand. For a column type SET it is allowed several values, of the highest 64 possible values. They are available in MySQL but do not exist in each application database.




In the next article, see the table with data types in MySQL.


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.