MySQL Interview Questions & Answers

  1. Question 1. What’s Mysql ?

    Answer :

    MySQL (pronounced “my ess cue el”) is an open source relational database management system (RDBMS) that uses Structured Query Language (SQL), the most popular language for adding, accessing, and processing data in a database. Because it is open source, anyone can download MySQL and tailor it to their needs in accordance with the general public license. MySQL is noted mainly for its speed, reliability, and flexibility.

  2. Question 2. What Is Ddl, Dml And Dcl ?

    Answer :

    If you look at the large variety of SQL commands, they can be divided into three large subgroups. Data Definition Language deals with database schemas and descriptions of how the data should reside in the database, therefore language statements like CREATE TABLE or ALTER TABLE belong to DDL. DML deals with data manipulation, and therefore includes most common SQL statements such SELECT, INSERT, etc. Data Control Language includes commands such as GRANT, and mostly concerns with rights, permissions and other controls of the database system.

  3. PHP Interview Questions

  4. Question 3. How Do You Get The Number Of Rows Affected By Query?

    Answer :

    SELECT COUNT (user_id) FROM users would only return the number of user_id’s.

  5. Question 4. If The Value In The Column Is Repeatable, How Do You Find Out The Unique Values?

    Answer :

    Use DISTINCT in the query, such as SELECT DISTINCT user_firstname FROM users; You can also ask for a number of distinct values by saying SELECT COUNT (DISTINCT user_firstname) FROM users;

  6. PHP Tutorial

  7. Question 5. How Do You Return The A Hundred Books Starting From 25th?

    Answer :

    SELECT book_title FROM books LIMIT 25, 100. The first number in LIMIT is the offset, the second is the number.

  8. PHP+MySQL Interview Questions

  9. Question 6. You Wrote A Search Engine That Should Retrieve 10 Results At A Time, But At The Same Time You’d Like To Know How Many Rows There’re Total. How Do You Display That To The User?

    Answer :

    SELECT SQL_CALC_FOUND_ROWS page_title FROM web_pages LIMIT 1,10; SELECT FOUND_ROWS(); The second query (not that COUNT() is never used) will tell you how many results there’re total, so you can display a phrase “Found 13,450,600 results, displaying 1-10”. Note that FOUND_ROWS does not pay attention to the LIMITs you specified and always returns the total number of rows affected by query.

  10. Question 7. How Would You Write A Query To Select All Teams That Won Either 2, 4, 6 Or 8 Games?

    Answer :

    SELECT team_name FROM teams WHERE team_won IN (2, 4, 6, 8)

  11. MySQL Tutorial
    Drupal Interview Questions

  12. Question 8. How Would You Select All The Users, Whose Phone Number Is Null?

    Answer :

    SELECT user_name FROM users WHERE ISNULL(user_phonenumber);

  13. Question 9. What Does This Query Mean: Select User_name, User_isp From Users Left Join Isps
    Using (user_id) ?

    Answer :

    It’s equivalent to saying SELECT user_name, user_isp FROM users LEFT JOIN isps WHERE users.user_id=isps.user_id

  14. MYSQL DBA Interview Questions

  15. Question 10. How Do You Find Out Which Auto Increment Was Assigned On The Last Insert?

    Answer :

    SELECT LAST_INSERT_ID() will return the last value assigned by the auto_increment function. Note that you don’t have to specify the table name.

  16. Drupal Tutorial

  17. Question 11. What Does -i-am-a-dummy Flag To Do When Starting Mysql?

    Answer :

    Makes the MySQL engine refuse UPDATE and DELETE commands where the WHERE clause is not present.

  18. PHP5 Interview Questions

  19. Question 12. On Executing The Delete Statement I Keep Getting The Error About Foreign Key Constraint Failing. What Do I Do?

    Answer :

    What it means is that so of the data that you’re trying to delete is still alive in another table. Like if you have a table for universities and a table for students, which contains the ID of the university they go to, running a delete on a university table will fail if the students table still contains people enrolled at that university. Proper way to do it would be to delete the offending data first, and then delete the university in question. Quick way would involve running SET foreign_key_checks=0 before the DELETE command, and setting the parameter back to 1 after the DELETE is done. If your foreign key was formulated with ON DELETE CASCADE, the data in dependent tables will be removed automatically.

  20. PHP Interview Questions

  21. Question 13. When Would You Use Order By In Delete Statement?

    Answer :

    When you’re not deleting by row ID. Such as in DELETE FROM techpreparation_com_questions ORDER BY timestamp LIMIT 1.

  22. WordPress Tutorial

  23. Question 14. How Can You See All Indexes Defined For A Table?

    Answer :

    SHOW INDEX FROM techpreparation_questions;

  24. Question 15. How Would You Change A Column From Varchar(10) To Varchar(50)?

    Answer :

    ALTER TABLE techpreparation_questions CHANGE techpreparation_content techpreparation_CONTENT VARCHAR(50).

  25. WordPress Interview Questions

  26. Question 16. How Would You Delete A Column?

    Answer :

    ALTER TABLE techpreparation_answers DROP answer_user_id.

  27. Joomla Tutorial

  28. Question 17. How Would You Change A Table To Innodb?

    Answer :

    ALTER TABLE techpreparation_questions ENGINE innodb;

  29. Joomla Interview Questions

  30. Question 18. When You Create A Table, And Then Run Show Create Table On It, You Occasionally Get Different Results Than What You Typed In. What Does Mysql Modify In Your Newly Created Tables?

    Answer :

    1. VARCHARs with length less than 4 become CHARs
    2. CHARs with length more than 3 become VARCHARs.
    3. NOT NULL gets added to the columns declared as PRIMARY KEYs
    4. Default values such as NULL are specified for each column

  31. PHP+MySQL Interview Questions

  32. Question 19. How Do I Find Out All Databases Starting With ‘tech’ To Which I Have Access To?

    Answer :

    SHOW DATABASES LIKE ‘tech%’;

  33. CakePHP Tutorial

  34. Question 20. How Do You Concatenate Strings In Mysql?

    Answer :

    CONCAT (string1, string2, string3)

  35. CakePHP Interview Questions

  36. Question 21. How Do You Get A Portion Of A String?

    Answer :

    SELECT SUBSTR(title, 1, 10) from techpreparation_questions;

  37. Question 22. What’s The Difference Between Char_length And Length?

    Answer :

    The first is, naturally, the character count. The second is byte count. For the Latin characters the numbers are the same, but they’re not the same for Unicode and other encodings.

  38. CodeIgniter Tutorial

  39. Question 23. How Do You Convert A String To Utf-8?

    Answer :

    SELECT (techpreparation_question USING utf8);

  40. CodeIgniter Interview Questions

  41. Question 24. What Do % And _ Mean Inside Like Statement?

    Answer :

    % corresponds to 0 or more characters, _ is exactly one character.

  42. Drupal Interview Questions

  43. Question 25. What Does + Mean In Regexp?

    Answer :

    At least one character. Appendix G. Regular Expressions from MySQL manual is worth perusing before the interview.

  44. PHP7 Tutorial

  45. Question 26. How Do You Get The Month From A Timestamp?

    Answer :

    SELECT MONTH(techpreparation_timestamp) from techpreparation_questions;

  46. PHP7 Interview Questions

  47. Question 27. How Do You Offload The Time/date Handling To Mysql?

    Answer :

    SELECT DATE_FORMAT(techpreparation_timestamp, ‘%Y-%m-%d’) from techpreparation_questions; A similar TIME_FORMAT function deals with time.

  48. MYSQL DBA Interview Questions

  49. Question 28. How Do You Add Three Minutes To A Date?

    Answer :

    ADDDATE(techpreparation_publication_date, INTERVAL 3 MINUTE)

  50. Question 29. What’s The Difference Between Unix Timestamps And Mysql Timestamps?

    Answer :

    Internally Unix timestamps are stored as 32-bit integers, while MySQL timestamps are stored in a similar manner, but represented in readable YYYY-MM-DD HH:MM:SS format.

  51. Question 30. How Do You Convert Between Unix Timestamps And Mysql Timestamps?

    Answer :

    UNIX_TIMESTAMP converts from MySQL timestamp to Unix timestamp, FROM_UNIXTIME converts from Unix timestamp to MySQL timestamp.

  52. Question 31. What Are Enums Used For In Mysql?

    Answer :

    You can limit the possible values that go into the table. CREATE TABLE months (month ENUM ‘January’, ‘February’, ‘March’,…); INSERT months VALUES (’April’);

  53. Question 32. How Are Enums And Sets Represented Internally?

    Answer :

    As unique integers representing the powers of two, due to storage optimizations.

  54. Question 33. How Do You Start And Stop Mysql On Windows?

    Answer :

    net start MySQL, net stop MySQL

  55. PHP5 Interview Questions

  56. Question 34. How Do You Start Mysql On Linux?

    Answer :

    /etc/init.d/mysql start

  57. Question 35. Explain The Difference Between Mysql And Mysql Interfaces In Php?

    Answer :

    mysql is the object-oriented version of mysql library functions.

  58. Question 36. What’s The Default Port For Mysql Server?

    Answer :

    3306 is the default port for MYSQL.

  59. WordPress Interview Questions

  60. Question 37. What Does Tee Command Do In Mysql?

    Answer :

    tee followed by a filename turns on MySQL logging to a specified file. It can be stopped by command note.

  61. Question 38. Can You Save Your Connection Settings To A Conf File?

    Answer :

    Yes, and name it ~/.my.conf. You might want to change the permissions on the file to 600, so that it’s not readable by others.

  62. Question 39. How Do You Change A Password For An Existing User Via Mysqladmin?

    Answer :

    mysqladmin -u root -p password “newpassword”

  63. Question 40. Use Mysqldump To Create A Copy Of The Database?

    Answer :

    mysqldump -h mysqlhost -u username -p mydatabasename > dbdump.sql

  64. Joomla Interview Questions

  65. Question 41. Have You Ever Used Mysql Administrator And Mysql Query Browser?

    Answer :

    Describe the tasks you accomplished with these tools.

  66. Question 42. What Are Some Good Ideas Regarding User Security In Mysql?

    Answer :

    There is no user without a password. There is no user without a user name. There is no user whose Host column contains % (which here indicates that the user can log in from anywhere in the network or the Internet). There are as few users as possible (in the ideal case only root) who have unrestricted access.

  67. CakePHP Interview Questions

  68. Question 43. Explain The Difference Between Myisam Static And Myisam Dynamic. ?

    Answer :

    In MyISAM static all the fields have fixed width. The Dynamic MyISAM table would include fields such as TEXT, BLOB, etc. to accommodate the data types with various lengths. MyISAM Static would be easier to restore in case of corruption, since even though you might lose some data, you know exactly where to look for the beginning of the next record.

  69. Question 44. What Does Myisamchk Do?

    Answer :

    It compressed the MyISAM tables, which reduces their disk usage.

  70. Question 45. Explain Advantages Of Innodb Over Myisam?

    Answer :

    Row-level locking, transactions, foreign key constraints and crash recovery.

  71. Question 46. Explain Advantages Of Myisam Over Innodb?

    Answer :

    Much more conservative approach to disk space management – each MyISAM table is stored in a separate file, which could be compressed then with myisamchk if needed. With InnoDB the tables are stored in tablespace, and not much further optimization is possible. All data except for TEXT and BLOB can occupy 8,000 bytes at most. No full text indexing is available for InnoDB. TRhe COUNT(*)s execute slower than in MyISAM due to tablespace complexity.

  72. Question 47. What Are Heap Tables In Mysql?

    Answer :

    HEAP tables are in-memory. They are usually used for high-speed temporary storage. No TEXT or
    BLOB fields are allowed within HEAP tables. You can only use the comparison operators = and <=>. HEAP tables do not support AUTO_INCREMENT. Indexes must be NOT NULL.

  73. Question 48. How Do You Control The Max Size Of A Heap Table?

    Answer :

    MySQL config variable max_heap_table_size.

  74. Question 49. What Are Csv Tables?

    Answer :

    Those are the special tables, data for which is saved into comma-separated values files. They cannot be indexed.

  75. Question 50. Explain Federated Tables?

    Answer :

    Introduced in MySQL 5.0, federated tables allow access to the tables located on other databases on other servers.

  76. Question 51. What Is Serial Data Type In Mysql?

    Answer :

    BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT

    SERIAL is an alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE

  77. Question 52. What Happens When The Column Is Set To Auto Increment And You Reach The Maximum Value For That Table?

    Answer :

    It stops incrementing. It does not overflow to 0 to prevent data losses, but further inserts are going to produce an error, since the key has been used already.

  78. Question 53. Explain The Difference Between Bool, Tinyint And Bit. ?

    Answer :

    Prior to MySQL 5.0.3: those are all synonyms. After MySQL 5.0.3: BIT data type can store 8 bytes of data and should be used for binary data.

  79. Question 54. Explain The Difference Between Float, Double And Real. ?

    Answer :

    FLOATs store floating point numbers with 8 place accuracy and take up 4 bytes.

    DOUBLEs store floating point numbers with 16 place accuracy and take up 8 bytes.

    REAL is a synonym of FLOAT for now.

  80. Question 55. If You Specify The Data Type As Decimal (5,2), What’s The Range Of Values That Can Go In This Table?

    Answer :

    999.99 to -99.99. Note that with the negative number the minus sign is considered one of the digits.

  81. Question 56. What Happens If A Table Has One Column Defined As Timestamp?

    Answer :

    That field gets the current timestamp whenever the row gets altered.

  82. Question 57. But What If You Really Want To Store The Timestamp Data, Such As The Publication Date Of The Article?

    Answer :

    Create two columns of type TIMESTAMP and use the second one for your real data.

  83. Question 58. Explain Data Type Timestamp Default Current_timestamp On Update
    Current_timestamp ?

    Answer :

    The column exhibits the same behavior as a single timestamp column in a table with no other timestamp columns.

  84. Question 59. What Does Timestamp On Update Current_timestamp Data Type Do?

    Answer :

    On initialization places a zero in that column, on future updates puts the current value of the timestamp in.

  85. Question 60. Explain Timestamp Default 2006:09:02 17:38:44? On Update Current_timestamp. ?

    Answer :

    A default value is used on initialization, a current timestamp is inserted on update of the row.

  86. Question 61. If I Created A Column With Data Type Varchar(3), What Would I Expect To See In Mysql Table?

    Answer :

    CHAR(3), since MySQL automatically adjusted the data type.

  87. Question 62. General Information About Mysql.

    Answer :

    MySQL is a very fast, multi-threaded, multi-user, and robust SQL (Structured Query Language) database server.

  88. Question 63. Why Sql Is A Database Management System?

    Answer :

    A database is a structured collection of data. It may be anything from a simple shopping list to a picture gallery or the vast amounts of information in a corporate network. To add, access, and process data stored in a computer database, you need a database management system such as MySQL. Since computers are very good at handling large amounts of data, database management plays a central role in computing, as stand-alone utilities, or as parts of other applications.

  89. Question 64. Why Use Mysql?

    Answer :

    MySQL is very fast, reliable, and easy to use. If that is what you are looking for, you should give it a try. MySQL also has a very practical set of features developed in very close cooperation with our users. You can find a performance comparison of MySQL to some other database managers on our benchmark page. See section 12.7 Using Your Own Benchmarks. MySQL was originally developed to handle very large databases much faster than existing solutions and has been successfully used in highly demanding production environments for several years. Though under constant development, MySQL today offers a rich and very useful set of functions. The connectivity, speed, and security make MySQL highly suited for accessing databases on the Internet.

  90. Question 65. How Mysql Optimizes Distinct ?

    Answer :

    DISTINCT is converted to a GROUP BY on all columns, DISTINCT combined with ORDER BY will in many cases also need a temporary table.

    When combining LIMIT # with DISTINCT, MySQL will stop as soon as it finds # unique rows.

    If you don’t use columns from all used tables, MySQL will stop the scanning of the not used tables as soon as it has found the first match.

    SELECT DISTINCT t1.a FROM t1,t2 where t1.a=t2.a;

    In the case, assuming t1 is used before t2 (check with EXPLAIN), then MySQL will stop reading from t2 (for that particular row in t1) when the first row in t2 is found.

  91. Question 66. How Mysql Optimizes Limit ?

    Answer :

    In some cases MySQL will handle the query differently when you are using LIMIT # and not using HAVING:

    If you are selecting only a few rows with LIMIT, MySQL will use indexes in some cases when it normally would prefer to do a full table scan.

    If you use LIMIT # with ORDER BY, MySQL will end the sorting as soon as it has found the first # lines instead of sorting the whole table.

    When combining LIMIT # with DISTINCT, MySQL will stop as soon as it finds # unique rows.

    In some cases a GROUP BY can be resolved by reading the key in order (or do a sort on the key) and then calculate summaries until the key value changes. In this case LIMIT # will not calculate any unnecessary GROUP BY’s.

    As soon as MySQL has sent the first # rows to the client, it will abort the query.

    LIMIT 0 will always quickly return an empty set. This is useful to check the query and to get the column types of the result columns.

    The size of temporary tables uses the LIMIT # to calculate how much space is needed to resolve the query.

  92. Question 67. Mysql – Speed Of Delete Queries ?

    Answer :

    If you want to delete all rows in the table, you should use TRUNCATE TABLE table_name. The time to delete a record is exactly proportional to the number of indexes. To delete records more quickly, you can increase the size of the index cache.

  93. Question 68. What Is The Difference Between Mysql_fetch_array And Mysql_fetch_object?

    Answer :

    mysql_fetch_array — Fetch a result row as an associative ARRAY, a numeric array, or both
    mysql_fetch_object — Fetch a result row as an OBJECT.

  94. Question 69. What Are The Different Table Present In Mysql?

    Answer :

    MyISAM : This is default. Based on Indexed Sequntial Access Method. The above SQL will create a MyISA table.

    ISAM : same

    HEAP : Fast data access, but will loose data if there is a crash. Cannot have BLOB, TEXT & AUTO INCRIMENT fields

    BDB : Supports Transactions using COMMIT & ROLLBACK. Slower that others.

    InoDB : same as BDB

  95. Question 70. What Is Primary Key?

    Answer :

    A primary key is a single column or multiple columns defined to have unique values that can be used as row identifications.

  96. Question 71. What Is Foreign Key?

    Answer :

    A foreign key is a single column or multiple columns defined to have values that can be mapped to a primary key in another table.

  97. Question 72. What Is Index?

    Answer :

    An index is a single column or multiple columns defined to have values pre-sorted to speed up data retrieval speed.

  98. Question 73. What Is Join?

    Answer :

    Join is data retrieval operation that combines rows from multiple tables under certain matching conditions to form a single row.

  99. Question 74. What Is Union?

    Answer :

    Join is data retrieval operation that combines multiple query outputs of the same structure into a single output. By default the MySQL UNION removes all duplicate rows from the result set even if you don’t explicit using DISTINCT after the keyword UNION.

    SELECT customerNumber id, contactLastname name
    FROM customers
    UNION
    SELECT employeeNurrber id, firstname name
    FROM employees

    id name

    103 Schmitt
    112 King
    114 Ferguson
    119 Labrune
    121 Bergulfsen

     

  100. Question 75. What Is Isam?

    Answer :

    ISAM (Indexed Sequential Access Method) was developed by IBM to store and retrieve data on secondary storage systems like tapes.

  101. Question 76. What Is Innodb?

    Answer :

    lnnoDB is a transaction safe storage engine developed by Innobase Oy (an Oracle company now).

  102. Question 77. What Is Bdb (berkeleydb)?

    Answer :

    BDB (BerkeleyDB) is transaction safe storage engine originally developed at U.C. Berkeley. It is now developed by Sleepycat Software, Inc. (an Oracle company now).

  103. Question 78. What Is Csv?

    Answer :

    CSV (Comma Separated Values) is a file format used to store database table contents, where one table row is stored as one line in the file, and each data field is separated with comma.

  104. Question 79. What Is Transaction?

    Answer :

    A transaction is a logical unit of work requested by a user to be applied to the database objects. MySQL server introduces the transaction concept to allow users to group one or more SQL statements into a single transaction, so that the effects of all the SQL statements in a transaction can be either all committed (applied to the database) or all rolled back (undone from the database).

  105. Question 80. What Is Commit?

    Answer :

    Commit is a way to terminate a transaction with all database changes to be saved permanently to the database server.

  106. Question 81. What Is Rollback?

    Answer :

    Rollback is a way to terminate a transaction with all database changes not saving to the database server.

  107. Question 82. How Many Groups Of Data Types?

    Answer :

    MySQL support 3 groups of data types as listed below:

    String Data Types – CHAR, NCHAR, VARCHAR, NVARCHAR, BINARY, VARBINARY, TINYBLOB, TINYTEXT, BLOB, TEXT, MEDIUMBLOB, MEDIUMTEXT, LONGBLOB, LONGTEXT, ENUM, SET.

    Numeric Data Types – BIT, TINYINT, BOOLEAN, SMALLINT, MEDIUMINT, INTEGER, BIGINT, FLOAT, DOUBLE, REAL, DECIMAL.

    Date and Time Data Types – DATE, DATETIME, TIMESTAMP, TIME, YEAR.

  108. Question 83. What Is The Differences Between Char And Nchar?

    Answer :

    Both CHAR and NCHAR are fixed length string data types. But they have the following differences:

    • CHARs full name is CHARACTER.
    • NCHARs full name is NATIONAL CHARACTER.
    • By default, CHAR uses ASCII character set. So 1 character is always stored as 1 byte.
    • By default, NCHAR uses Unicode character set. NCHAR data are stored in UTF8 format. So 1 character could be stored as 1 byte or upto 4 bytes.
    • Both CHAR and NCHAR columns are defined with fixed lengths in units of characters.
  109. Question 84. How To Escape Special Characters In Sql Statements?

    Answer :

    There are a number of special characters that needs to be escaped (protected), if you want to include them in a character string. Here are some basic character escaping rules:

    • The escape character () needs to be escaped as ().
    • The single quote (‘) needs to be escaped as (‘) or (“) in single-quote quoted strings.
    • The double quote () needs to be escaped as (“) or (““) in double-quote quoted strings.
    • The wild card character for a single character () needs to be escaped as (_).
    • The wild card character for multiple characters (%) needs to be escaped as (%).
    • The tab character needs to be escaped as (t).
    • The new line character needs to be escaped as (n).
    • The carriage return character needs to be escaped as (r).
  110. Question 85. How To Concatenate Two Character Strings?

    Answer :

    If you want concatenate multiple character strings into one, you need to use the CONCAT() function. Here are some good examples:

    SELECT CONCAT(’Welcome’,’ to’) FROM DUAL;
    Welcome to
    SELECT CONCAT(wj’,’center’,’.com’) FROM DUAL;
    ap6am.com
  111. Question 86. How To Enter Characters As Hex Numbers?

    Answer :

    If you want to enter characters as HEX numbers, you can quote HEX numbers with single quotes and a prefix of (X), or just prefix HEX numbers with (Ox). A HEX number string will be automatically converted into a character string, if the expression context is a string. Here are some good examples:

    SELECT X313233’ FROM DUAL;
    123
    SELECT 0x414243 FROM DUAL;
    ABC
  112. Question 87. How To Enter Boolean Values In Sql Statements?

    Answer :

    If you want to enter Boolean values in SQL statements, you use (TRUE), (FALSE), (true), or (false). Here are some good examples:

    SELECT TRUE, true, FALSE, false FROM DUAL;
  113. Question 88. How To Convert Numeric Values To Character Strings?

    Answer :

    You can convert numeric values to character strings by using the CAST(value AS CHAR) function as shown in the following examples:

    SELECT CAST(4123.45700 AS CHAR) FROM DUAL;
    4123.45700
  114. Question 89. How To Get Rid Of The Last 2 0’s?

    Answer :

    SELECT CAST(4.12345700E+3 AS CHAR) FROM DUAL;
    4123.457
    SELECT CAST(1/3 AS CHAR);
    0.3333

  115. Question 90. How To Use In Conditions?

    Answer :

    An IN condition is single value again a list of values. It returns TRUE, if the specified value is in the list. Otherwise, it returns FALSE. Some examples are :

    SELECT 3 IN (1,2,3,4,5) FROM DUAL;
    1
    SELECT 3 NOT IN (1,2,3,4,5) FROM DUAL;
    0
    SELECT Y’ IN (‘F’,’Y’,I) FROM DUAL; 
    1
  116. Question 91. How To Use Like Conditions?

    Answer :

    A LIKE condition is also called pattern patch. There are 3 main rules on using LIKE condition:

    • is used in the pattern to match any one character.
    • % is used in the pattern to match any zero or more characters.
    • ESCAPE clause is used to provide the escape character in the pattern.
  117. Question 92. How To Present A Past Time In Hours, Minutes And Seconds?

    Answer :

    If you want show an article was posted “n hours n minutes and n seconds ago’, you can use the TIMEDIFF(NOWO, pastTime) function as shown in the following are:

    SELECT TIMEDIFF(NOWO, ‘2006-07-01 04:09:49’) FROM DUAL;
    06:42:58
    SELECT TIM E_FORMAT(TI M EDI FF( NOWO, ‘2006-06-30 04:09:49’), 
     ‘%H hours, %i minutes and %s seconds ago.’) FROM DUAL;
    30 hours, 45 minutes and 22 seconds ago.
  118. Question 93. How To Add A New Column To An Existing Table In Mysql?

    Answer :

    ALTER TABLE tip ADD COLUMN author VARCHAR(40);
    Query OK, 1 row affected (0.18 sec)
    Records: 1 Duplicates: 0 Warnings: 0

  119. Question 94. How To Delete An Existing Column In A Table?

    Answer :

    ALTER TABLE tip DROP COLUMN create_date;
    Query OK, 1 row affected (0.48 sec)
    Records: 1 Duplicates: 0 Warnings: 0

  120. Question 95. How To Rename An Existing Column In A Table?

    Answer :

    ALTER TABLE tip CHANGE COLUMN subject title VARCHAR(60);

  121. Question 96. How To Rename An Existing Table In Mysql?

    Answer :

    ALTER TABLE tip RENAME TO faq;

  122. Question 97. How To Create A Table Index In Mvsql?

    Answer :

    If you have a table with a lots of rows, and you know that one of the columns will be used often as a search criteria, you can add an index for that column to improve the search performance. To add an index, you can use the “CREATE INDEX” statement as shown in the following script:

    mysql> CREATE TABLE tip (id INTEGER PRIMARY KEY,
    subject VARCHAR(80) NOT NULL, 
    description VARCHAR(256) NOT NULL, 
    create_date DATE NULL);  Query OK, 
    0 rows affected (0.08 sec)
    mysql> CREATE INDEX tip_subject ON tip(subject);
    Query OK,
    0 rows affected (0.19 sec)
    Records: 0 Duplicates: 0 Warnings: 0
  123. Question 98. How To Get A List Of Indexes Of An Existing Table?

    Answer :

    If you want to see the index you have just created for an existing table, you can use the “SHOW INDEX FROM tableName” command to get a list of all indexes in a given table.

  124. Question 99. How To Drop An Existing Index In Mysql?

    Answer :

    If you don’t need an existing index any more, you should delete it with the “DROP INDEX indexName ON tableName” statement. Here is an example SQL script :

    mysqi> DROP INDEX tip_subject ON tip;
    Query OK, 0 rows affected (0.13 sec)
    Records: 0 Duplicates: 0 Warnings: 0
  125. Question 100. How To Drop An Existing View In Mysql?

    Answer :

    If you have an existing view, and you dont want it anymore, you can delete it by using the “DROP VIEW viewName” statement

  126. Question 101. How To Create A New View In Mysql?

    Answer :

    You can create a new view based on one or more existing tables by using the

    “CREATE VIEW viewName AS selectStatement” .

  127. Question 102. How To Increment Dates By 1111 Mysql?

    Answer :

    If you have a date, and you want to increment it by 1 day, you can use the DATE_ADD(date, INTERVAL 1 DAY) function. You can also use the date interval add operation as “date + INTERVAL 1 DAY.