Frequently Asked Questions about MySQL Interview (2)

  1. Archive mode and non-archive mode? Why can the archive mode be restored to any time?
    Archiving is to save the redo log file to
    the specified location by copying the operating system file before the redo log file is overwritten . The collection of saved redo log files is called archived redo log files, and the process of copying is called archiving. In the archive log (ARCHIVELOG) mode, the database archives the redo log files. In NOARCHIVELOG mode, redo log files will not be archived. Since the non-archive mode will not be saved before being overwritten, the redo log file of the database before a certain time is lost, and it cannot be restored to before being overwritten. The archive mode has redo log files at any time, so it can be restored to any time.
  2. How to increase the frequency of log switching? The
    interval of log switching can be controlled by the parameter ARCHIVE_LAG_TARGET, in seconds. By reducing the time interval, the switching frequency of logs can be increased. For example, the following code:
    SQL> ALTER SYSTEM SET ARCHIVE_LAG_TARGET=50 SCOPE=both;
    Through the above command, the log can be switched every 50 seconds.
  3. There are three columns ABC in the table, which are implemented by SQL statements: when column A is greater than column B, select column A otherwise select column B; when column B is greater than column C, select column B otherwise select column C.
select (case when a>b then a else b end ), (case when b>c then b esle c end) 
from table_name

4. For a date-judgment sql statement, please take out all the records whose date (SendTime field) in the tb_send table is that day? (SendTime field is datetime type, including date and time)?

select * from tb where datediff(dd,SendTime,getdate())=0

5. There is a table with 3 fields: Chinese, Mathematics, and English. Among them, there are 3 records representing 70 points for Chinese,
80 points for Mathematics , and 58 points for English. Please use a sql statement to query these three records and display them according to the following conditions (and write your thoughts): greater than or equal to 80 means excellent , Greater than or equal to 60 means passing, less than 60 points means failing

select
(case when 语文>=80 then '优秀
when 语文>=60 then '及格'
else '不及格') as 语文,
(case when 数学>=80 then '优秀'
when 数学>=60 then '及格'
else '不及格') as 数学,
(case when 英语>=80 then '优秀'
when 英语>=60 then '及格'
else '不及格') as 英语,
from table

6. Does the custom function support output parameters?
A custom function can accept zero or more input parameters, and its return value can be a numeric value or a table, but the custom function does not support output parameters.
7. Why delete unused triggers in time? After the
trigger is defined , Each time the trigger event is executed, the trigger is activated and the statement in the trigger is executed. If the requirements change, and the trigger does not change or delete the trigger, the trigger will still execute the old statement, which will affect the integrity of the new data. Therefore, the triggers that are no longer used should be deleted in time.
8. What is a unique index? A
unique index can ensure that the index column does not contain duplicate values. In the case of a multi-column unique index, the index can ensure that each value combination in the indexed column is unique.
For example, if a unique index full_name is created on the combination of last_name, first_name, and middle_initial columns, no two people in the table can have the same full name. Both clustered index and non-clustered index can be unique.
Therefore, as long as the data in the column is unique, you can create a unique clustered index and multiple unique non-clustered indexes on the same table. Only when uniqueness is a characteristic of the data itself, it makes sense to specify a unique index. If you must implement uniqueness to ensure data integrity, you should create a UNIQUE or PRIMARY KEY constraint on the column instead of creating a unique index.
9. Why is UNION ALL faster than UNION?
Because when you use UNION, you need to delete duplicate records, but you don't need to delete when you use UNION ALL. So
if you know that the query that requires UNION is unlikely to have duplicate data, you must use UNION ALL

Guess you like

Origin blog.csdn.net/weixin_44051191/article/details/109168633