SQL veri tipi demek ne tür verileri depolanacağıyla belirlenmesinde kullanılır. Yani bir sayı mı tutacaksınız yoksa bir metin mi yoksa, resim, tarih vs…

Bu yazımızda database’ de bir tablo oluştururken veri tülerinin ne olması gerektiğini öğreneceğiz. Tablolarınızdaki her bir sutun(kolon) sizde bir veri tipi isteyecektir. Bunları belirlemeden tablonuzu oluşturamazsınız. Bu yüzden tablo oluşturmadan önce veri tiplerimize karar vermemiz çok önemlidir. En uygun şekilde kolonların veri tiplerini belirlemek database’ inizin ne kadar yer kaplayacağını ve performansını etkileyecektir.

SQL Veri Tipleri

Şimdi gelelim veri türlerimize ve ne işe yaradıklarına. SQL’ de 4 ana başlıkta veri tipleri mevcuttur.

1. Metinsel SQL Veri Tipi (String data types)
Data typeDescriptionMax sizeStorage
char(n)Fixed width character string8,000 charactersDefined width
varchar(n)Variable width character string8,000 characters2 bytes + number of chars
varchar(max)Variable width character string1,073,741,824 characters2 bytes + number of chars
textVariable width character string2GB of text data4 bytes + number of chars
ncharFixed width Unicode string4,000 charactersDefined width x 2
nvarcharVariable width Unicode string4,000 characters
nvarchar(max)Variable width Unicode string536,870,912 characters
ntextVariable width Unicode string2GB of text data
binary(n)Fixed width binary string8,000 bytes
varbinaryVariable width binary string8,000 bytes
varbinary(max)Variable width binary string2GB
imageVariable width binary string2GB
2. Nümerik SQL Veri Tipi (Number data types)
Data typeDescriptionStorage
bitInteger that can be 0, 1, or NULL
tinyintAllows whole numbers from 0 to 2551 byte
smallintAllows whole numbers between -32,768 and 32,7672 bytes
intAllows whole numbers between -2,147,483,648 and 2,147,483,6474 bytes
bigintAllows whole numbers between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,8078 bytes
decimal(p,s)Fixed precision and scale numbers.Allows numbers from -10^38 +1 to 10^38 –1.

The p parameter indicates the maximum total number of digits that can be stored (both to the left and to the right of the decimal point). p must be a value from 1 to 38. Default is 18.

The s parameter indicates the maximum number of digits stored to the right of the decimal point. s must be a value from 0 to p. Default value is 0

5-17 bytes
numeric(p,s)Fixed precision and scale numbers.Allows numbers from -10^38 +1 to 10^38 –1.

The p parameter indicates the maximum total number of digits that can be stored (both to the left and to the right of the decimal point). p must be a value from 1 to 38. Default is 18.

The s parameter indicates the maximum number of digits stored to the right of the decimal point. s must be a value from 0 to p. Default value is 0

5-17 bytes
smallmoneyMonetary data from -214,748.3648 to 214,748.36474 bytes
moneyMonetary data from -922,337,203,685,477.5808 to 922,337,203,685,477.58078 bytes
float(n)Floating precision number data from -1.79E + 308 to 1.79E + 308.The n parameter indicates whether the field should hold 4 or 8 bytes. float(24) holds a 4-byte field and float(53) holds an 8-byte field. Default value of n is 53.4 or 8 bytes
realFloating precision number data from -3.40E + 38 to 3.40E + 384 bytes
3. Tarihsel Veri Tipleri (Date data types)
Data typeDescriptionStorage
datetimeFrom January 1, 1753 to December 31, 9999 with an accuracy of 3.33 milliseconds8 bytes
datetime2From January 1, 0001 to December 31, 9999 with an accuracy of 100 nanoseconds6-8 bytes
smalldatetimeFrom January 1, 1900 to June 6, 2079 with an accuracy of 1 minute4 bytes
dateStore a date only. From January 1, 0001 to December 31, 99993 bytes
timeStore a time only to an accuracy of 100 nanoseconds3-5 bytes
datetimeoffsetThe same as datetime2 with the addition of a time zone offset8-10 bytes
timestampStores a unique number that gets updated every time a row gets created or modified. The timestamp value is based upon an internal clock and does not correspond to real time. Each table may have only one timestamp variable
4. Diğer SQL Veri Tipi (Other data types)
Data typeDescription
sql_variantStores up to 8,000 bytes of data of various data types, except text, ntext, and timestamp
uniqueidentifierStores a globally unique identifier (GUID)
xmlStores XML formatted data. Maximum 2GB
cursorStores a reference to a cursor used for database operations
tableStores a result-set for later processing

 


0 yorum

Bir yanıt yazın

Avatar placeholder

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

Bu site, istenmeyenleri azaltmak için Akismet kullanıyor. Yorum verilerinizin nasıl işlendiği hakkında daha fazla bilgi edinin.