الانتقال إلى المحتوى

مالفرق بين الـ Constraint على مستوى جدول ومستوى عمود وايهما افضل؟؟


roro2005

Recommended Posts

السلام عليكم جميعا اعضاء ومشرفي المنتدى ورحمة الله وبركاته
سؤالي عن الـ Constraint
مالفرق بين الـ Constraint على مستوى جدول ومستوى عمود وايهما افضل؟؟
ارجو المساعده العاجلة
اختكم

رابط هذا التعليق
شارك



Column Level Constraints refers Only One Column .Which does
not have the column name at declaration time .
Ex :
 Create table emp
     ( empno number primary Key,
      --,
      --);



Table Level constraints refers one or more than one column .
Which does have column name at declaration time.
Ex:

Create table emp
     ( empno number ,
      --,
      --,
      Constraints pk_con primary Key(empno));



All constraints can be created as Column and Table level
(like, primary key, foreign key,unique)

Not Null constraints can only be created as column level
constraints .

so A column constraint is specified as part of a column definition and applies only to that column.

A table constraint is declared independently from a column definition and can apply to more than one column in a table

Ex:

CREATE TABLE CLASS (
ROOM NUMBER(10) , 
SUBJECT VARCHAR2(200),
CODE VARCHAR2(50) NOT NULL,  /*  Column level constraint*/
ID NUMBER(8,2),
CLASS_DATE DATE, 
CONSTRAINT PK_1 PRIMARY KEY (ROOM));  /*   table level

رابط هذا التعليق
شارك

وعليكم السلام و رحمة الله

(طبعا انا جديد في المنتدى) ,,, لكن ان شاء الله اقدر افيد


حسب دراستي السابقة للـ SQL انه لايوجد فرق بين الاثنين الفرق فقط في الساينتكس syntax
والفرق في الساينتكس : انه في الـ column level ندخل الـ constraint بعد الكولمن مباشرة ,,,, اما في table level ندخل الـ constraint بعد ادخال جميع الكولمنز .
وهذا مثال (بالنسبة لل check)

هذا للـ column level

create table employee(eno number(3),ename varchar2(20),esal number constraint
esal_chk check(esal<=5000),esex char(1) constraint esex_chk check(esex='f' or esex='m'))


وهنا للـ table level

create table employee(eno number not null,
ename varchar2(20),
esal number,
esex number,
dname varchar2(20),
design varchar2(20),
company varchar2(20),
constraint esal_chk check(esal>0 and esal<10000),
constraint esex_chk check(esex ='f' or esex ='m'))



أما بالنسبة لأيهما أفضل ,,, فالله أعلم ,,, لأنني مجرد طالب
والعذر اذا كان هناك اي خطأ فأنا مبتدئ

رابط هذا التعليق
شارك

انضم إلى المناقشة

يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.

زائر
أضف رد على هذا الموضوع...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   تمت استعادة المحتوى السابق الخاص بك.   مسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

جاري التحميل
×
×
  • أضف...

برجاء الإنتباه

بإستخدامك للموقع فأنت تتعهد بالموافقة على هذه البنود: سياسة الخصوصية