Archive

Posts Tagged ‘database’

Working with Time on Oracle

March 29, 2013 Leave a comment

As I’ve mentioned in my previous post, we were working on a hospital database for our case study, and that includes storage of Appointments (that’s future date + time). I noticed it odd for Oracle that it doesn’t display time, by default. And it doesn’t have a datatype specialized for time. So I found this tweak using SQL, which you might consider helpful as well.

Let’s say my APPOINTMENT table looks like this:

oracle_time_02

ON SQL:

ALTER SESSION SET NLS_DATE_FORMAT='DD-MON-YYYY HH24:MI';

You may need to enter this before every session, because Oracle’s default setting doesn’t include time at all. HH24 means you will be using a 24-hour time setting – that’s less troublesome than having to deal with AM/PM texts, which you need to parse (I think).

INSERT INTO appointment (appt_no, appt_date, confirm_status, cpt_code, patient_no, prov_no, room_no)
VALUES('APT0011', TO_DATE('05-Feb-2013 14:30', 'DD-MON-YYYY HH24:MI'), 'T', '97810', 'P00019', 'PR0008', '102');
SELECT appt_no, TO_CHAR(appt_date, 'DD-MON-YYYY HH24:MI') appt_date, patient_no
FROM appointment;

Notice that I used the TO_DATE() function to store the time data and the TO_CHAR() to retrieve/display it.

RESULT:
oracle_time_01

NOTE: The Time data will be displayed only upon query (via TO_CHAR()), not in the Object Browser. Well, at least we know it’s stored.

Let me know if it worked for you (or not).

Categories: Machine fix Tags: , ,

Correcting optionalities at MS Visio

March 29, 2013 3 comments

The past month, I was studying the basics of databases, and among the things I had to learn along the way are Entity Relations (ER). Databases are composed of tables (called entities) that are to be connected based on their dependencies towards each other. Our instructor introduced us Microsoft Visio as a good tool to make Entity Relationship Diagrams.

In an ERD, each table has its own columns (called attributes) with at least one of them set as primary key to identify uniquely to that table. Depending on the relationship between entities, a table can inherit the primary key of another table as foreign key, and thus become a child to the table (parent) it is referencing to. Out-bound parent links can be set as mandatory or optional, and the child link cardinalities can be set such that parent-to-child relationships are:

Mandatory

Optional

1 TO 0 or more

0 or 1 TO 0 or more
1 TO 1 or more

0 or 1 TO 1 or more
1 TO 0 or 1

0 or 1 TO 0 or 1
1 TO 1

0 or 1 TO 1
1 to Range [at least N, at most M]

0 or 1 to Range [at least N, at most M]

In visual representation, the entity closest to the crow’s feet is the child.

When we were doing our case study on a hospital database, I had trouble trying to create a mandatory link from the parent entity (which should be displayed as two straight lines, instead of just a line and a ring). (Shown below)

ms_visio_00

In this scenario, ROOM is the parent entity and MEDICAL_SERVICE is the child entity and we need to fix their relation (highlighted below).

ms_visio_01

Under Miscellaneous > Child has parent, what we are supposed to do is to uncheck Optional.

ms_visio_02

The problem (the problem!) is that it’s grayed out (disabled). So …

Here’s the workaround:
Under Definition, disconnect associated relations. Make sure the key you choose is the one being inherited (in this case, Room_No)

ms_visio_03

Go back to Miscellaneous > Relationship type, make sure it’s set to Non-identifying. Under Child has parent, you can now (finally) uncheck Optional.

ms_visio_04

and voila!

ms_visio_05

There’s the mandatory relation right there.