Set - 5

Question 1 :

What are the other commands to know the structure of a table using MySQL commands except EXPLAIN command? 

Answer :

DESCRIBE table_name;


Question 2 :

How can we find the number of rows in a table using MySQL?

Answer :

Use this for MySQL
SELECT COUNT(*) FROM table_name;


Question 3 :

What's the difference between md5(), crc32() and sha1() crypto on PHP?

Answer :

The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.


Question 4 :

How can we find the number of rows in a result set using PHP?

Answer :

Here is how can you find the number of rows in a result set in PHP:

$result = mysql_query($any_valid_sql, $database_link);
$num_rows = mysql_num_rows($result);
echo "$num_rows rows found";

 


Question 5 :

How many ways we can we find the current date using MySQL?

Answer :

SELECT CURDATE();
SELECT CURRENT_DATE();
SELECT CURTIME();
SELECT CURRENT_TIME();


Question 6 :

Give the syntax of GRANT commands?

Answer :

The generic syntax for GRANT is as following

GRANT [rights] on [database] TO [username@hostname] IDENTIFIED BY [password]

Now rights can be:
a) ALL privilages
b) Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc.

We can grant rights on all databse by usingh *.* or some specific database by database.* or a specific table by database.table_name.


Question 7 :

Give the syntax of REVOKE commands?

Answer :

The generic syntax for revoke is as following

REVOKE [rights] on [database] FROM [username@hostname]

Now rights can be:
a) ALL privileges
b) Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc.

We can grant rights on all database by using *.* or some specific database by database.* or a specific table by database.table_name.


Question 8 :

What is the difference between CHAR and VARCHAR data types? 

Answer :

CHAR is a fixed length data type. CHAR(n) will take n characters of storage even if you enter less than n characters to that column. For example, "Hello!" will be stored as "Hello! " in CHAR(10) column. 

VARCHAR is a variable length data type. VARCHAR(n) will take only the required storage for the actual number of characters entered to that column. For example, "Hello!" will be stored as "Hello!" in VARCHAR(10) column.


Question 9 :

How can we encrypt and decrypt a data present in a mysql table using mysql?

Answer :

AES_ENCRYPT() and AES_DECRYPT()


Question 10 :

Will comparison of string "10" and integer 11 work in PHP?

Answer :

Yes, internally PHP will cast everything to the integer type, so numbers 10 and 11 will be compared.


Question 11 :

What is the functionality of MD5 function in PHP? 

Answer :

string md5(string)
It calculates the MD5 hash of a string. The hash is a 32-character hexadecimal number.


Question 12 :

How can I load data from a text file into a table? 

Answer :

The MySQL provides a LOAD DATA INFILE command. You can load data from a file. Great tool but you need to make sure that:

a) Data must be delimited
b) Data fields must match table columns correctly


Question 13 :

How can we know the number of days between two given dates using MySQL?

Answer :

Use DATEDIFF()
SELECT DATEDIFF(NOW(),'2006-07-01');

 


Question 14 :

How can we change the name of a column of a table?

Answer :

This will change the name of column:

ALTER TABLE table_name CHANGE old_colm_name new_colm_name

 


Question 15 :

How can we change the data type of a column of a table? 

Answer :

This will change the data type of a column:

ALTER TABLE table_name CHANGE colm_name same_colm_name [new data type]