Tag Archive Index (non-clustered)

Byphunsanit

SSMS: Default Constraint Prefixe

เคยสงสัยว่าเวลา SSMS มันสร้าง PK (Primary Key), FK (Foreign Key), UQ (Unique Constraint) แล้วตั้งชื่อให้ เป็น Prefix พวกนี้มันยังพอที่จะจับได้ว่า ย่อมาจาก อะไร แต่ IX นี่คืออะไร เลขโรมันเหรอ ความจริงคือ Naming Convention รูปแบบหนึ่ง โดย SQL Server จะใช้


Prefix
MeaningExampleหน้าที่ให้จดจำ
PK_Primary KeyPK_Employeesไม่ซ้ำใครในตาราง
ไม่ NULL
มีตัวเดียว
FK_Foreign KeyFK_Employees_Departmentsเชื่อมกับตารางอื่น ๆ
UQ_Unique ConstraintUQ_Employees_Emailไม่ซ้ำตามเงื่อนไข
IX_Index (non-clustered)IX_Employees_LastNameสารบัญ ชี้ว่าอยู่ตรงไหน
CX_Clustered Index (rarely used by SSMS)(usually PK handles this)สารบัญ เกิดตาม PK
DF_Default ConstraintDF_Employees_CreatedDateค่าเริ่มต้น
CK_Check ConstraintCK_Employees_Salaryตรวจสอบข้อมูล