SQL When to use which data type

Hi, I was wondering when I will use different data types. Like in my table, how can I decide what to use: nvarchar, nchar, varchar, varbinary, etc.

Examples:

What would I use for a column ...:

Phone number,
Address,
First Name, Last Name,
Email,
ID number,
etc. 

Thanks for any help!

+3
source share
6 answers

As a rule, I would not define anything as a "number" field, if I were not going to do arithmetic on it, even if the data themselves were numerical.

The telephone field is one example. I would define it as varchar.

+5
source

Varchar, Integer and Bit cover 99% of my daily use.

+2
source

. , , .

n..char Unicode, , Unicode , "-n" . nchar char , nvarchar varchar , . , , , .

Microsoft SQL Server 2005, , , char varchar.

+2

N * (NVARCHAR, NCHAR, NTEXT) Unicode. , "" (VARCHAR, CHAR, TEXT), Unicode .

TEXT , , CHAR, .

VARCHAR . , CHAR (a CHAR (20) , 5 ). 15 ).

, , ( ).

+1

, : VARCHAR() ( ), , , , VARCHAR(100) , , , .. VARCHAR(200) URL- .

, . , 30 ( , ), , - . , a VARCHAR, , VARCHAR(MAX) TEXT , .

, , , VARCHAR : varchar MySQL. , , - VARCHAR s.

0
source

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


All Articles