Skip to main content

الجزء الخامس: قيد التحقق Check Constraint

الجزء الخامس: قيد التحقق Check Constraint

قيد التحقق يستخدم لتحديد قيم المدخلة في الحقل, وهو عبارة عن تعبير منطقي(صح|خطأ) ,مثال على ذلك في حقل العمر نحن نعرف ان القيمة يجب ان تكون مابين سن 16 – 50 فأذا كان العمر المدخل هو 13 او -199 او 999 يتم استرجاع قيمة الخطاً وبذلك لم يدرج السجل ضمن الجدول وكذلك يجدر الملاحظة اذا كان حقل العمر يسمح بقيمة باطلة Null  فشرط المنطقي يسترجع صح لأن الحقل اصلاً محدد ان يكون Nullable



لأضافة حقل العمر في جدول tblPerson  :
alter table tblPerson
add age int Null

من اجل اضافة قيد التحقق عن طريق جملة الأستعلام:
Alter table {TABLE_NAME}
add constraint {Constraint_Name}
Check {Boolean expression}

alter table tblPerson
add constraint CK_tblPerson_age
check (age>16 AND age<50)

عند اضافة سجل داخل جدول كالأتي:
insert into tblPerson values(7,'K','k@k@.co',Null,1)

فالناتج هو:
Msg 547, Level 16, State 0, Line 1
The INSERT statement conflicted with the CHECK constraint "CK_tblPerson_age". The conflict occurred in database "test", table "dbo.tblPerson", column 'age'.
The statement has been terminated.


ولكن عند اضافة السجل التالي:
insert into tblPerson(ID,Name,Email,GenderID,age) values(9,'e','e@e@.co',Null,Null)
فالناتج هو:

(1 row(s) affected)

لحذف قيد التحقق Check constraint   عن طريق جملة الأستعلام:

alter table tblPerson
drop constraint CK_tblPerson_age



لأضافة قيد التحقق Check constraint  بأستخدام الواجهة الرسومية:

اذهب الى ملف القيود Constraints وأضغط على زر الماوس الأيمن واختر اضافة قيد جديد :New Constraint



لكون القيد الذي سنقوم بأضافته هو قيد التحقق فيستوجب ان نضغط على زر التعبير Expression :




قم بأضافة التعبير لحقل العمر كالأتي:




قم بتخزين التغييرات التي طرأت على ذلك الجدول بالضغط على زر الماوس الأيمن على اسم شريط الجدول واختيار حفظ الجدول:


Comments

Popular posts from this blog

How To Play .srt Subtitles File in Windows Media Player

How To Play .srt Subtitles File in Windows Media Player links: https://sourceforge.net/projects/wmpsub/ wmp,.srt Subtitles File in Windows Media Player,How To Play .srt Subtitles File in Windows Media Player,How To,Safaa Al-Hayali,saf3al2a,srt subtitle in WMP,Windows,Windows Media Player,media,.ass,local subtitles

How to fix the disk is write protected

in this video tutorial, I'll show you how to remove/solve/fix the disk is write protected from USB flash drive. To download the necessary 2 files: Download >  SAFAA_ALHAYALI.IMG  - 1.18 MB Download >  Win32DiskImager-0.9.5-install.exe - 11.7 MB write protection,remove write protection,write protected,How to fix the disk is write protected,how to solve the disk is write protected,how to remove the disk is write protected,USB write protected,fix USB write protected,fix HDD write protected,how to,windows,USB flash drive ERROR,fix USB flash drive write protected,USB flash drive write protected

Virtual Box : How to Increase Disk Size - Windows

How to increase disk size or disk storage in oracle virtual box the command you have to use: vboxmanage.exe modifymedium "[YourPathToVdiFileOfYourVirtualMachine]" --resize [NUMBER] virtual,box,vbox,oracle,partition,size,disk,increase,resize,windows,10,microsoft,vdi,vboxmanage,configuration,Safaa AL-Hayali,saf3al2a,Oracle,VirtualBox,How to,windows 10