الانتقال إلى المحتوى
View in the app

A better way to browse. Learn more.

مجموعة مستخدمي أوراكل العربية

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Task جامد عن ال Constraint

Featured Replies

بتاريخ:



We have atable Employees
the columns is

Employeeid
Employeesname
birthdate
hiredate
email
salary

we want the Constraint like this

Employeeid is primary key

Employeesname is not null

birthdate must be more than 20 year

hiredate must be less than or equal sysdate

email must contain ( @ and . ) email format

salary must be more than 100



what is the perfect or the best code to create this table ??? i'll wait for your replay . thank you







بتاريخ:

انا عملت الجدول اللى انت عاوزه ..... بس بالنسبة لل date فدى لما نيجى نحطها فى قيد ال check
بالشروط اللى احنا عوزنها ( اللى انت حددتها ) فلازم الشروط دى تكون على النحو التالى :-

  1. The condition must be a Boolean expression that can be evaluated using the values in the row being inserted or updated.
  2. The condition cannot contain subqueries or sequences.
  3. The condition cannot include the SYSDATE, UID, USER, or USERENV SQL functions.
  4. The condition cannot contain the pseudocolumns LEVEL, PRIOR, or ROWNUM.
  5. The condition cannot contain a user-defined SQL function.



علشان كده انا شوفت انه من الافضل و الاسهل اننا نستخدم ال trigger
لتنفيذ الشروط الموضوعه على date ( اللى هما بالنسبة للعموديين BIRTHDATE , HIREDATE ) .

و هذا هو الكود :-

CREATE TABLE employees_oug (
employeeid NUMBER PRIMARY KEY,
employeesname VARCHAR2(20) NOT NULL,
birthdate DATE ,
hiredate DATE DEFAULT SYSDATE ,
email VARCHAR2(60) UNIQUE CHECK ( email LIKE '%@%.%'),
salary NUMBER CHECK ( salary > 100 ) );

--- create trigger for birthdate column :-
CREATE OR REPLACE TRIGGER emp_bd
  BEFORE INSERT OR UPDATE OF birthdate ON employees_oug
  FOR EACH ROW
BEGIN IF NOT :NEW.birthdate < (SYSDATE - 20 * 365)
  THEN
     raise_application_error (-20202,
                              'Employee cannot be less than 20 years old.'
                             );
  END IF;
END;
/

--- create trigger for hiredate column :-
CREATE OR REPLACE TRIGGER emp_hd
  BEFORE INSERT OR UPDATE OF hiredate ON employees_oug
  FOR EACH ROW
BEGIN IF NOT :NEW.hiredate <= SYSDATE
  THEN
     raise_application_error
                   (-20202,
                    'Employee''s Hire date cannot be insert in future date.'
                   );
  END IF;
END;
/
-- that's all ...... and now you have to insert rows to be ensure from my Codes



اتمنى ان تكون الفكرة واضحة .

و بالتوفيق.

تم تعديل بواسطة hanyfreedom

بتاريخ:
  • كاتب الموضوع

الف الف شكر يا اخى Hany Freedom الفكرة واضحة وشكرا على الاهتمام والرد




شكرا

بتاريخ:
  • كاتب الموضوع



انا جربت الحل بتاعك يا أخ هانى وهو طبعا حل ممتاز بس فيه حاجة انا لما دخلت الميل( email ) لقيتة ممكن يقبل منى الاتى :



[email protected]

ww@d . kd

انت واخد بالك يعنى ممكن يدخل ال @ وبعدها على طول يدخل ال . او ممكن يدخل مسافة ودى مش الفورمات بتاعة الميل

فهل ليها حل

--------------------------------------------
لكن طبعا انا بشكرك جدا جدا وكفاية انك شرفتى بالرد على الموضوع والاهتمام والحل اللى انا استفدت منة كتير


شكرا

بتاريخ:

اخى الكريم MSHEGYPT
انت ذكرت هذا النص تحديداً عند طلبك لعمود الاميل :-

email must contain ( @ and . ) email format

و من ثم انا قمت بعمل ما طلبت ..... و لكن اذا كنت تريد وضع constraints كافية لحفظ التنسيق المعتاد لأى أميل
فأن هذه ال constraints يجب ان تتصف بالتالى :-

1) No embedded spaces
2) '@' can't be the first character of an email address
3) '.' can't be the last character of an email address
4) There must be a '.' after '@'
5) Only one '@' sign is allowed
6) Domain name should end with at least 2 character extension
7) can't have patterns like '.@' and '..'



و من ثم فأن ال constraints هنا يجب ان تتبع ال Regular Expression
فلا يوجد اى طريقة اخرى غيرها .

ضيف هذا الكود لتعديل قيود حقل ال email :-

ALTER TABLE employees_oug
MODIFY email VARCHAR2(60)
CHECK (REGEXP_LIKE(email,'^[a-z0-9._%+-]+@[a-z0-9.-_]+\.[a-z]{2,4}$'));



و اعمل جمل ال insert دلوقتى علشان تتأكد من دقة القيود الجديدة على حقل الاميل .

و بالتوفيق

بتاريخ:
  • كاتب الموضوع

الف الف شكر يا اخى Hany Freedom الفكرة واضحة وشكرا على الاهتمام والرد




شكرا

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

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

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

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

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

Account

Navigation

البحث

إعداد إشعارات المتصفح الفورية

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.