Test your skills through the online practice test: MySQL Quiz Online Practice Test

Related differences

Ques 66. What Are Date and Time Functions in MySQL?

MySQL offers a number of functions for date and time values:

► ADDDATE(date, INTERVAL expr unit) - Adding days to a date. Same as DATE_ADD().
► ADDTIME(time1, time2) - Adding two time values together.
► CURDATE() - Returning the current date. Same as CURRENT_DATE().
► CURTIME() - Returning the current time. Same as CURRENT_TIME().
► DATE(expression) - Returning the date from the expression.
► DATEDIFF(date1, date2) - Returning dates difference in days.
► DATE_ADD(date, INTERVAL expr unit) - Adding days to a date.
► DATE_SUB(date, INTERVAL expr unit) - Subtracting days from a date.
► DATE_FORMAT(date, format) - Returning a character string representing a date.
► DAY(date) - Returning an integer representing the day of the month. Same as DAYOFMONTH()
► DAYNAME(date) - Returning the name of week day.
► DAYOFMONTH(date) - Returning an integer representing the day of the month.
► DAYOFWEEK(date) - Returning an integer representing the day of the week.
► DAYOFYEAR(date) - Returning an integer representing the day of the year.

Is it helpful? Add Comment View Comments
 

Ques 67. What Are the Differences between CHAR and VARCHAR?

CHAR and VARCHAR are both ASCII character data types by default. But they have the following major differences:

► CHAR stores values in fixed lengths. Values are padded with space characters to match the specified length.
► VARCHAR stores values in variable lengths. Values are not padded with any characters. But 1 or 2 extra bytes are added to store the length of the data.

The table below shows you a good comparison of CHAR and VARCHAR data types:
Value CHAR(4) Length

'' ' ' 4 bytes

'ab' 'ab ' 4 bytes

'abcd' 'abcd' 4 bytes


Value VARCHAR(4) Length

'' '' 1 byte

'ab' 'ab' 3 bytes

'abcd' 'abcd' 5 bytes

Is it helpful? Add Comment View Comments
 

Ques 68. What Is TIMESTAMP in MySQL?

A TIMESTAMP data type allows you to record a date and time like DATETIME data type. But it has some interesting features when used on a table column:

► The first TIMESTAMP column in a table will be assigned with the current date and time, if it is not listed in an INSERT statement.
► The first TIMESTAMP column in a table will be assigned with the current date and time, if it is not listed in an UPDATE statement.
► If a TIMESTAMP column is assigned with NULL, the current date and time will be persisted to this column.
► You can turn off the default current date and time on INSERT by defining the column with "DEFAULT 0".
► The tutorial exercise below provides you 2 equivalent ways to create a TIMESTAMP column:

CREATE TABLE links (lastDate TIMESTAMP);

CREATE TABLE links (lastDate TIMESTAMP
DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP);

Is it helpful? Add Comment View Comments
 

Ques 69. What Are the Differences between BINARY and VARBINARY?

Both BINARY and VARBINARY are both binary byte data types. But they have the following major differences:

► BINARY stores values in fixed lengths. Values are padded with 0x00.
► VARBINARY stores values in variable lengths. Values are not padded with any bytes. But 1 or 2 extra bytes are added to store the length of the data.

Is it helpful? Add Comment View Comments
 

Ques 70. How Many Ways to Get the Current Time?

There are 8 ways to get the current time:

SELECT NOW() FROM DUAL;
2006-07-01 10:02:41

SELECT CURRENT_TIME() FROM DUAL;
10:02:58

SELECT SYSDATE() FROM DUAL;
2006-07-01 10:03:21

mysql> SELECT CURRENT_TIMESTAMP() FROM DUAL;
2006-07-01 10:04:03

SELECT LOCALTIME() FROM DUAL;
2006-07-01 10:07:37

mysql> SELECT LOCALTIMESTAMP() FROM DUAL;
2006-07-01 10:08:08

mysql> SELECT UTC_TIME() FROM DUAL;
14:09:22

mysql> SELECT UTC_TIMESTAMP() FROM DUAL;
2006-07-01 14:09:49

Is it helpful? Add Comment View Comments
 

Most helpful rated by users: