Monday, 4 May 2015

System-Related Functions in mysql

System-Related Functions

SELECT CONNECTION_ID();
SELECT DATABASE();
SELECT VERSION();

The function takes one argument, which is the network address. For example, the following SELECT
statement returns the numeric value for the address 127.0.0.1:

SELECT INET_ATON(‘127.0.0.1’);

When you execute the statement, MySQL returns the value of 2130706433. You can also take a numeric value such as this and convert it to an IP address by using the following function:

SELECT INET_NTOA(2130706433);

FOUND_ROWS() function allows you to determine the number of the entire result set

SELECT FOUND_ROWS();

Executing this statement displays the number of rows that would have been returned by the original
SELECT statement,

LAST_INSERT_ID() function allows you to retrieve the last value that was inserted in an AUTO_INCREMENT column.

SELECT LAST_INSERT_ID();

Now try out the FOUND_ROWS() function. Before you do that, you must create a SELECT statement that includes the SQL_CALC_FOUND_ROWS option and the LIMIT clause. Execute the following SQL statement at the mysql command prompt:

SELECT SQL_CALC_FOUND_ROWS DVDName
FROM DVDs
WHERE StatID=’s2’
ORDER BY DVDName
LIMIT 2;


Now you can create a SELECT statement that includes the FOUND_ROWS() function. 
Execute the following SQL statement at the mysql command prompt:

SELECT FOUND_ROWS();

No comments:

Post a Comment