Interview :: MySQL
How to view the database in MySQL?
Working with the MySQL server, it is a common task to view or list the available databases. We can view all the databases on the MySQL server host using the following command:
Auto Increment is a constraint that automatically generates a unique number while inserting a new record into the table. Generally, it is used for the primary key field in a table. In MySQL, we can set the value for an AUTO_INCREMENT column using the ALTER TABLE statement as follows:
MySQL uses the LIMIT keyword, which can be used to limit the result set. It will allow us to get the first few rows, last few rows, or range of rows. It can also be used to find the second, third, or nth highest salary. It ensures that you have use order by clause to sort the result set first and then print the output that provides accurate results. The following query is used to get the second highest salary in MySQL:
There are some other ways to find the second highest salary in MySQL, which are given below:
This statement uses subquery and IN clause to get the second highest salary:
This query uses subquery and < operator to return the second highest salary:
- TRUNCATE is a DDL command, and DELETE is a DML command.
- It is not possible to use Where command with TRUNCATE QLbut you can use it with DELETE command.
- TRUNCATE cannot be used with indexed views, whereas DELETE can be used with indexed views.
- The DELETE command is used to delete data from a table. It only deletes the rows of data from the table while truncate is a very dangerous command and should be used carefully because it deletes every row permanently from a table.
There are only six Triggers allowed to use in the MySQL database.
- Before Insert
- After Insert
- Before Update
- After Update
- Before Delete
- After Delete
Tables that are present in memory is known as HEAP tables. When you create a heap table in MySQL, you should need to specify the TYPE as HEAP. These tables are commonly known as memory tables. They are used for high-speed storage on a temporary basis. They do not allow BLOB or TEXT fields.
BLOB is an acronym that stands for a large binary object. It is used to hold a variable amount of data.
There are four types of the BLOB.
- TINYBLOB
- BLOB
- MEDIUMBLOB
- LONGBLOB
The differences among all these are the maximum length of values they can hold.
TEXT is a case-insensitive BLOB. TEXT values are non-binary strings (character string). They have a character set, and values are stored and compared based on the collation of the character set.
There are four types of TEXT.
- TINYTEXT
- TEXT
- MEDIUMTEXT
- LONGTEXT
A trigger is a set of codes that executes in response to some events.
Heap tables:
Heap tables are found in memory that is used for high-speed storage temporarily. They do not allow BLOB or TEXT fields.
Heap tables do not support AUTO_INCREMENT.
Indexes should be NOT NULL.
Temporary tables:
The temporary tables are used to keep the transient data. Sometimes it is beneficial in cases to hold temporary data. The temporary table is deleted after the current client session terminates.
Main differences:
The heap tables are shared among clients, while temporary tables are not shared.
Heap tables are just another storage engine, while for temporary tables, you need a special privilege (create temporary table).
FLOAT stores floating-point numbers with accuracy up to 8 places and allocate 4 bytes. On the other hand, DOUBLE stores floating-point numbers with accuracy up to 18 places and allocates 8 bytes.