Showing posts with label Data Type. Show all posts
Showing posts with label Data Type. Show all posts

Thursday, March 31, 2011

Data Type

การสร้าง Table ควรกำหนดโครงสร้างให้เหมาะสมกับที่ใช้งาน ไม่อย่างนั้นอาจเปลืองพื้นที่โดยไม่จำเป็น

ประเภท

ชนิด

 หมายเหตุ

 ขนาด (Byte)

 Integer

 tinyint

 0 to 255

 1



 smallint

 -32,768 to 32,767

 2



 int

 -2,147,483 to 2,147,483,647

 4



 bigint

 -263 to (263 - 1)

 8

 Money

 money

 +- 922,337,203,685,477.5808

 8



 smallmoney

 +- 214,748.3648

 4

 Numeric

 decimal(p,s)

 p คือจำนวนหลักข้างหน้าจุดและข้างหลังจุดทศนิยมรวมกัน

 s คือจำนวนหลักข้างหลังจุดทศนิยม



 numeric(p,s)

p

 Byte





 1-9

 5





 10-19

 9





 20-28

 13





 29-38

 17

 DateTime

 datetime

 1 Jan 1753 to 31 Dec 9999

 8 (ความละเอียดถึง 3.33 ms)



 smalldatetime

 1 Jan 1900 to 6 June 2079

 4 (ความละเอียด 1 นาที)

 String

 char(n)

 จองเท่าไรก็เก็บเท่านั้น

 1 char ใช้พื้นที่ 1 Byte



 varchar(n)

 เก็บเท่าที่มีจริงแต่ไม่เกิน n

 n มากสุดได้ 8000



 varchar(max)

 เป็น Text มากสุด = GB





 nchar(n)

 เหมือน char

 1 char ใช้พื้นที่ 2 Byte



nvarchar(n)

 เหมือน varchar n มากสุด 4000

(เพื่อรับรองภาษาต่างประเทศเช่นจีน)
หมายเหตุ: สำหรับเราใช้แค่  ไทย-อังกฤษ จึงใช้ varchar ก็พอ ไม่เปลืองพื้นที่เก็บ