154k views
1 vote
Write a SELECT statement without a FROM clause that uses the NOW function (research how to use NOW function in SQL) to create a row with these columns: today_unformatted The NOW function unformatted today_formatted The NOW function in this format: DD-Mon-YYYY This displays a number for the day, an abbreviation for the month, and a four-digit year. As mentioned, do not use FROM clause, as you are not selecting data from any table. Hint: Use AS command. (10 points) Important style guideline: For better readability of code, you should put each attribute in SELECT clause on a separate line and tab them (2 times) in this query.

1 Answer

5 votes

Answer:

ALTER TABLE "table name"

ADD COLUMN today_unformated DATE DEFAULT AS (SELECT TOCHAR( NOW( ) :: date, " dd-Mon-yyyy")

Step-by-step explanation:

The SQL query statements above add a new column called "today_unformated" to a table and set its default value to the current date of the local machine, with its format set to a number as day and year and a three-letter abbreviation as the month.

User Kansuler
by
4.3k points