بتاريخ: 19 أبريل 200817 سنة comment_126966 We have atable Employeesthe columns is EmployeeidEmployeesnamebirthdatehiredateemailsalarywe want the Constraint like this Employeeid is primary keyEmployeesname is not nullbirthdate must be more than 20 yearhiredate must be less than or equal sysdateemail must contain ( @ and . ) email formatsalary must be more than 100what is the perfect or the best code to create this table ??? i'll wait for your replay . thank you تقديم بلاغ
بتاريخ: 20 أبريل 200817 سنة comment_127053 انا عملت الجدول اللى انت عاوزه ..... بس بالنسبة لل date فدى لما نيجى نحطها فى قيد ال check بالشروط اللى احنا عوزنها ( اللى انت حددتها ) فلازم الشروط دى تكون على النحو التالى :- The condition must be a Boolean expression that can be evaluated using the values in the row being inserted or updated. The condition cannot contain subqueries or sequences. The condition cannot include the SYSDATE, UID, USER, or USERENV SQL functions. The condition cannot contain the pseudocolumns LEVEL, PRIOR, or ROWNUM. 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 اتمنى ان تكون الفكرة واضحة .و بالتوفيق. تم تعديل 20 أبريل 200817 سنة بواسطة hanyfreedom تقديم بلاغ
بتاريخ: 21 أبريل 200817 سنة كاتب الموضوع comment_127141 الف الف شكر يا اخى Hany Freedom الفكرة واضحة وشكرا على الاهتمام والرد شكرا تقديم بلاغ
بتاريخ: 21 أبريل 200817 سنة كاتب الموضوع comment_127142 انا جربت الحل بتاعك يا أخ هانى وهو طبعا حل ممتاز بس فيه حاجة انا لما دخلت الميل( email ) لقيتة ممكن يقبل منى الاتى :[email protected] ww@d . kd انت واخد بالك يعنى ممكن يدخل ال @ وبعدها على طول يدخل ال . او ممكن يدخل مسافة ودى مش الفورمات بتاعة الميل فهل ليها حل --------------------------------------------لكن طبعا انا بشكرك جدا جدا وكفاية انك شرفتى بالرد على الموضوع والاهتمام والحل اللى انا استفدت منة كتير شكرا تقديم بلاغ
بتاريخ: 22 أبريل 200817 سنة comment_127194 اخى الكريم 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 دلوقتى علشان تتأكد من دقة القيود الجديدة على حقل الاميل .و بالتوفيق تقديم بلاغ
بتاريخ: 22 أبريل 200817 سنة كاتب الموضوع comment_127215 الف الف شكر يا اخى Hany Freedom الفكرة واضحة وشكرا على الاهتمام والرد شكرا تقديم بلاغ
انضم إلى المناقشة
يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.