Back to Dashboard

MySql Interview Questions

Answer: MySQL is an open-source DBMS which is developed and distributed by Oracle Corporation. It is supported by most of the popular operating systems, such as Windows, Linux, etc. It can be used to develop different types of applications but it is mainly used for developing web applications. MySQL uses GPL (GNU General Public License) so that anyone can download and install it for developing those applications which will be published or distributed freely. But if a user wants to develop any commercial application using MySQL then he/she will need to buy the commercial version of MySQL.
Some important features of MySQL are mentioned below:
  • It is reliable and easy to use too.
  • It is a suitable database software for both large and small applications.
  • Anyone can install and use it at no cost.
  • It is supported by many well-known programming languages, such as PHP, Java, C++, PERL, etc.
  • It supports standard SQL (Structured Query Language).
  • The open-source license of MySQL is customizable. Hence, a developer can modify it according to the requirements of the application.
The default port number of MySQL is 3306.
Answer: The database table uses a primary key to identify each row uniquely. It is necessary to declare the primary key on those tables that require to create a relationship among them. One or more fields of a table can be declared as the primary key. When the primary key of any table is used in another table as the primary key or another field for making a database relation, then it is called a foreign key. The differences between these two keys are mentioned below:
  1. The primary key uniquely identifies a record, whereas foreign key refers to the primary key of another table.
  2. The primary key can never accept a NULL value but foreign key accepts a NULL value. When a record is inserted in a table that contains the primary key then it is not necessary to insert the value on the table that contains this primary key field as the foreign key.
  3. When a record is deleted from the table that contains the primary key then the corresponding record must be deleted from the table containing the foreign key for data consistency. But any record can be deleted from the table that contains a foreign key without deleting a related record of another table.
Both CHAR and VARCHAR data types are used to store string data in the field of the table. The differences between these data types are mentioned below:
  1. CHAR data type is used to store fixed-length string data and the VARCHAR data type is used to store variable-length string data.
  2. The storage size of the CHAR data type will always be the maximum length of this data type and the storage size of VARCHAR will be the length of the inserted string data. Hence, it is better to use the CHAR data type when the length of the string will be the same length for all the records.
  3. CHAR is used to store small data whereas VARCHAR is used to store large data. CHAR works faster and VARCHAR works slower.