Why are these specific data types necessary when creating database tables?

Take the following create table statement:

create table fruit
{
  count int,
  name varchar(32),
  size float
}

Instead of these specific data types, why not "string", "number", "boolean" or better, without specifying any data types at all.

What are the technical reasons for having these specific data types? (unlike a typical or missing data type)

+3
source share
10 answers

Imagine 20 million rows in a table with an int column, where all numbers are from 1 to 10.

tinyint, 1 . int, 4 . , 60 .

" " , , , . , , . , , , .

+4

, .

.

MyNumberField : "1234", 13, 35, "1234afgas"

"1234afgas"?

.

+3

tinyint = 1

smallint = 2

int = 4

bigint = 8

, , , bigint

(char, varchar .. ..)

... A int... ..

+3

, : string, boolean, number. , . , .

+2

, , . , "1" , , 1, "1" ...

"1" , col1 + col2 2 "11"?

+2

, , , SQLite (http://www.sqlite.org/).

+1

, , , , IBM Universe DB (aka Pick). Db , , "".

, .

0

. ? . x, x. , .

, , , . , N X, , X.

, , , -X X , -Z Z. ( ). .

, , , . , , , .

0

, , , - 8 , , , . (, nchar (8))

( , ) .

0

. , . , , , , , .

One of the other core functions of a database is data integrity. The more accurately you specify what data should be stored in the field, the less likely you are to accidentally save incorrect data there. This is similar to why your C compiler is so picky about the code you write: you should prefer to deal with errors at compile time rather than run-time errors.

0
source

Source: https://habr.com/ru/post/1729281/


All Articles