It's UWAweek 47

help1402

This forum is provided to promote discussion amongst students enrolled in CITS1402 Relational Database Management Systems.

Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.

How do I ask a good question?
Displaying the 2 articles in this topic
Showing 2 of 684 articles.
Currently 114 other people reading this forum.


 UWA week 31 (2nd semester, week 2) ↓
SVG not supported

Login to reply

👍?
helpful
11:32am Fri 2nd Aug, Tuan H.

Hi all, I have a question related to data type when defining a new table. When I define my table, I realise that we define the attribute "DOB" as DATE, but when I want to enter data into my table, as follows: e.g. INSERT INTO Branch(DOB) VALUES ('1995-10-31') The value I inserted into the table is a string, so when I did additional test to see whether this data is automatically transformed to DATE data type, I encountered an unexpected result. There are some solutions I came up with after research: 1. Use DATE() --> INSERT INTO Branch(DOB) VALUES (DATE '1995-10-31'): the expected result is not 1995-10-31 2. According to the textbook, numeric data should be in a quotation mark --> INSERT INTO Branch(DOB) VALUES (1995-10-31): SQL does the subtraction. Can anyone help me on this problem? Thank you so much.


 UWA week 32 (2nd semester, week 3) ↓
SVG not supported

Login to reply

👍x2
helpful
8:23am Mon 5th Aug, Adam W.

There is also the fact we are using the SQLite implementation of SQL, which has a few slight differences, one of which is DATE types (from https://www.sqlite.org/datatype3.html): --- 2.2. Date and Time Datatype SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values: TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS"). REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar. INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC. Applications can choose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions. --- The value used for the date is effectively the time value, as you can see below, you can use the level of precision you require, e.g. we dont need hours/mins/secs. From: https://www.sqlite.org/lang_datefunc.html 2. Time Values A time-value can be in any of the following formats shown below. The value is usually a string, though it can be an integer or floating point number in the case of format 12. YYYY-MM-DD YYYY-MM-DD HH:MM YYYY-MM-DD HH:MM:SS YYYY-MM-DD HH:MM:SS.SSS YYYY-MM-DDTHH:MM YYYY-MM-DDTHH:MM:SS YYYY-MM-DDTHH:MM:SS.SSS HH:MM HH:MM:SS HH:MM:SS.SSS now DDDDDDDDDD --- For our purposes, we would be dealing with dates as strings, SQLite would still have all the functionality we need for later use like using dates in comparisons (direct comparison, between, before, after, etc.). You just need to be sure you use the formatting we mention, and we should have also referenced dates correctly for you to use in the SQL code. Thanks, Adam. "Tuan Hoang" <24*9*8*6@s*u*e*t*u*a*e*u*a*> wrote:
> Hi all, > I have a question related to data type when defining a new table. > When I define my table, I realise that we define the attribute "DOB" as DATE, but when I want to enter data into my table, as follows: > e.g. INSERT INTO Branch(DOB) VALUES ('1995-10-31') > The value I inserted into the table is a string, so when I did additional test to see whether this data is automatically transformed to DATE data type, I encountered an unexpected result. There are some solutions I came up with after research: > 1. Use DATE() --> INSERT INTO Branch(DOB) VALUES (DATE '1995-10-31'): the expected result is not 1995-10-31 > 2. According to the textbook, numeric data should be in a quotation mark --> INSERT INTO Branch(DOB) VALUES (1995-10-31): SQL does the subtraction. > Can anyone help me on this problem? Thank you so much.

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  8:08AM Aug 25 2024
Privacy policy