Question

Using oracle sql for creating database nd inserting data I want to write a constraint on...

Using oracle sql for creating database nd inserting data
I want to write a constraint on the date of birth so that any age will be only be from 21 to 60
This constraint should be calculated automatically using sysdate or the system date
Hint: data type is date


Also for the car year model I want to write a constraint to check that it is not older than 10 years (the field data type is integer) I want it using sysdate coz it wil be used for long time
0 0
Add a comment Improve this question Transcribed image text
Answer #1

For checking date constraint you have to create table with check condition on date of birth. To calculate age you can use sysdate() or getdate() function and find the difference between date of birth and sytem date (current date) then apply condition for age between 21 to 60.

You have to write a query like this to create table..

create table employee (empid number(5), name varchar(20),birthdate date check (DATEDIFF(year,birthdate,getdate()) >=21 and DATEDIFF(year,birthdate,getdate()) <=60 ))

  

Note: You can use sysdate() or getdate().

Like check condition on age, you can use check condition for car model also.

Like this

create table car (carid number(5), model varchar(20),purchasedate date check (DATEDIFF(year,purchasedate,getdate()) <=10))

Add a comment
Know the answer?
Add Answer to:
Using oracle sql for creating database nd inserting data I want to write a constraint on...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am using Oracle SQL and am new to it. I have seven tables, one of...

    I am using Oracle SQL and am new to it. I have seven tables, one of them is a subtable of two of the others. I need to do the following queries: 1. List all Patients and what Bed they are assigned to 2. List all patients who had Treatments and what Treatment they received 3. List all patients who had tests and what Test they had 4. List the employees (doctors, nurses, etc.) who assisted each patient. 5. List...

  • I am using oracle sql developer to create some queries to generated reports and it is...

    I am using oracle sql developer to create some queries to generated reports and it is not working. I am not sure how to use count, group by, and order by. Help me fix my query and explain to me how you did, so can do it next time. Also, I have to convert this query to a stored procedure, so can you help me do it too? Here is my query: SELECT COUNT(GUEST.FIRSTNAME), GUEST.FIRSTNAME, GUEST.LASTNAME, GUEST.GUESTTYPE, RESERVATION.RESERVATIONDATE, GUEST.EMAIL, FROM...

  • Answer the following and explain so I can double check my answers If you use the Management Studio to create a database, the Studio will automatically create a database file plus a ________________...

    Answer the following and explain so I can double check my answers If you use the Management Studio to create a database, the Studio will automatically create a database file plus a ______________________ file. 10 points    QUESTION 2 When you use the Management Studio to create a check constraint, you can specify whether you want the constraint enforced for insert or __________________ operations. 10 points    QUESTION 3 When you use the Management Studio to create a database, including its tables...

  • SQL Query Question: I have a database with the tables below, data has also been aded...

    SQL Query Question: I have a database with the tables below, data has also been aded into these tables, I have 2 tasks: 1. Add a column to a relational table POSITIONS to store information about the total number of skills needed by each advertised position. A name of the column is up to you. Assume that no more than 9 skills are needed for each position. Next, use a single UPDATE statement to set the values in the new...

  • Description Design a database that contains 3-5 related tables to model a scenario of your intere...

    Description Design a database that contains 3-5 related tables to model a scenario of your interest. You should be somewhat familiar with the scenario that you choose to make informed design decisions. For example, if you want to design a database for a small business, you need to know the business logistic in the company. Other examples for your database are a database for a bookstore, a gym (e.g., YMCA), or a small organization. Do step 1 Step 1: Write...

  • Part I. Create a library check-out database using Microsoft SQL Server that stores data about books,...

    Part I. Create a library check-out database using Microsoft SQL Server that stores data about books, patrons, and the check-out process. Books (BookID, BookName, Author, YearPublished) Patrons (PatronsID, PatronsName, PatronsAddress, PatronsBirthday) CheckInOut (TransactionID, PatronID, BookID, CheckOutDate, NumDay, ReturnDate, Late, Fees, Paid) - the NumDay field contains the number of days patrons can keep the book, if the return date is over the number of day, then the Late field will have a Y value and a fee of $1.00 per...

  • Question 1.Write a SQL statement for each of the following questions based on the above tables...

    Question 1.Write a SQL statement for each of the following questions based on the above tables (50 Points). 1) Create “Enrollment” table. 2) Change the credits of “Database” course from 2 to 3. 3) List the course titles (not Course_No) and grades John Doe had taken. 4) Calculate average of Café Balance, and name new field as Average Balance. 5) Create a roster for “Database” course (list student ID, last name, first name, major, and status for each student enrolled...

  • Your project will require you to develop a database design to solve a real-life data management...

    Your project will require you to develop a database design to solve a real-life data management problem. It can be any problem in your work environment or for another organization, for example, a bookstore (think of how Amazon uses databases), a course management system (think of how a university manages courses), a bank (think of how your bank works), and an online auction site (think of how Ebay works). You will develop a database to solve this problem You will...

  • Please provide the relation algebra, the oracle SQL code and the output tuples for the following (Answer #6 only the BONUS question). I have the others actually I have the BONUS, but I want to compar...

    Please provide the relation algebra, the oracle SQL code and the output tuples for the following (Answer #6 only the BONUS question). I have the others actually I have the BONUS, but I want to compare with your solution to make sure I did it correctly. Thank you very much! LAB exercises 2 Write the Oracle DML query codes for the following questions and take the screen shot of the output. 1. Retrieve the name and address of all employees...

  • The lab for this week addresses taking a logical database design (data model) and transforming it...

    The lab for this week addresses taking a logical database design (data model) and transforming it into a physical model (tables, constraints, and relationships). As part of the lab, you will need to download the zip file titled CIS336Lab3Files from Doc Sharing. This zip file contains the ERD, Data Dictionary, and test data for the tables you create as you complete this exercise. Your job will be to use the ERD Diagram found below as a guide to define the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT