Frequently Asked Questions about MySQL Interview (1)

Frequently Asked Questions about MySQL Interview (1)

  1. How to deal with when the STR function encounters a decimal?
    When using the STR function, if the number is a decimal, when converting to a string data type, only the integer part is returned. If the number after the decimal point is greater than or equal to 5, the integer will be rounded section
  2. Is it right that the more indexes are built, the better?
    Reasonable indexes can increase the speed of the query, but not the more indexes the better. When the insert statement is executed, the database must index the newly inserted records. So too many indexes will slow down the insert operation. In principle, only the fields used in the query are indexed.
  3. What is the role of the view?
    1. The database view hides the complexity of the data.
    2. Database views are conducive to controlling user access to certain columns in the table.
    3. The database view makes user query simple.
    The view is a virtual table whose content is defined by the query. Like a real table, the view contains a series of named column and row data. However, the view does not exist in the database as a set of stored data values. The row and column data comes from the table referenced by the query that defines the view, and is dynamically generated when the view is referenced. For the referenced base table, the view is similar to filtering. The filtering of the defined view can come from one or more tables in the current or other databases, or other views. Distributed queries can also be used to define views that use multiple heterogeneous source data. This method is useful if there are several different servers that store data in different regions of the organization, and you need to combine data with similar structures on these servers. There are no restrictions on querying through views, and there are few restrictions on data modification through them.
  4. What is the difference between a stored procedure and a custom function?
    Stored procedures, powerful, can perform a series of database operations including modifying tables, and can also be created as stored procedures that run automatically when SQL Server starts. And custom functions, user-defined functions cannot be used to perform a set of operations that modify the state of the global database.
    Stored procedures, you can use non-deterministic functions. Custom numbers, it is not allowed to build non-deterministic functions in the body of user-defined functions.
    A stored procedure can return a record set. Custom functions can return table variables or have any number of output parameters.
    The return value of a stored procedure cannot be directly quoted and must be called separately. Custom function, its return value can be directly quoted, that is, you can directly select * from function.
  5. There are multiple records of Id in a table, find out all the records of this id, and display the total number of records.select id, Count(*) from tb group by id having count(*)>1
    select * from(select count(ID) as count from table group by ID)T where T.count>1
  6. Why group by and order by make the query slower? The
    group by and order by operations usually need to create a temporary table to process the results of the query, so if there are many query results, it will seriously affect the performance
  7. What is the difference between delete, truncate and drop? The
    Delete command is used to delete all or part of the data rows in the table. After executing delete, the user needs to commit or rollback the transaction to execute the delete or undo the delete. The delete command will trigger this All delete triggers on the table.
    Truncate deletes all the data in the table. This operation cannot be rolled back, nor will it trigger the trigger on this table. Truncate is faster than delete and takes up less space.
    The Drop command deletes a table from the database, all data rows, indexes and permissions will also be deleted, all DML triggers will not be triggered, and this command cannot be rolled back.
  8. Briefly describe the database design process.
    Demand analysis: It is mainly to accurately collect user information needs and processing needs, and organize and analyze the collected results to form a demand statement.
    Conceptual structure design: Synthesize, summarize, and abstract user needs to form a conceptual model that has nothing to do with the specific DBMS (usually an ER model).
    Logical structure design: Transform the conceptual model of the conceptual structure design into a data model supported by a specific DBMS, establish and optimize the database logical model, and design external models for various users and applications.
    Physical structure design: Select the physical structure for the designed logical model, including storage structure and access method, and establish the database physical model.
    Implementation and maintenance: Implementation is to use DLL language to establish a database model, load actual data into the database, and establish a real database.
    The maintenance phase is to evaluate, adjust and modify the running database.
  9. Can I not specify the field name when inserting a record?
    No matter which INSERT syntax is used, the correct number of VALUES must be given. If you do not provide a field name, you must provide a value for each field, otherwise an error message will be generated. If you want to omit certain fields in the INSERT operation, these fields need to meet certain conditions: the column is defined to allow null values; or the default value is given when the table is defined. If no value is given, the default value will be used.
  10. The difference and applicability of local indexes and global indexes
    For local indexes, each table partition corresponds to an index partition. When the table partition changes, the index maintenance is
    automatically performed by the database . For a global index, you can choose whether to partition, and the partition of the index may not correspond to the table partition. When performing maintenance operations on partitions, it usually results in INVALDED of the global index, which must be REBUILD after the operation is completed.
  11. What is the relationship between transactions and locks?
    Various mechanisms can be used to ensure data integrity, such as constraints, triggers, and transactions and locks. The relationship between transactions and locks is very close. A transaction contains a series of operations. These operations are either all successful or all failed. Multiple transactions are managed through the transaction mechanism to ensure the consistency of the transaction. The lock is used in the transaction to protect the specified resource to prevent other users from modifying the other one that has not been completed.
    The data in the transaction.
  12. Talk about your understanding of the
    index. Index is a list of keywords for several data rows. When querying data, you can quickly locate the data block where the record to be accessed is located through the keywords in the index, thereby greatly reducing the I /O times, so performance can be significantly improved.
  13. Talk about your understanding of
    transactions. A transaction starts when COMMIT, ROLLBACK, connect to the database, or the first executable SQL statement, and ends when a COMMIT, ROLLBACK statement, or exit the database. If a DDL statement is included in a transaction, the COMMIT statement is implicitly executed before and after the DDL statement to start or end a transaction. If a transaction must be cancelled before commit due to some failure or because the user changed his mind, the database is restored to the state before the execution of these statements and procedures. The ROLLBACK statement can be used to undo or roll back a transaction at any time before the COMMIT command. You can roll back the entire transaction or part of the transaction, but you cannot roll back a transaction that has been committed. The ROLLBACK command to roll back part of the transaction is: ROLLBACK to savepoint storage point name, storage point is a mark put into the transaction by the user, used to indicate a location that can be rolled back. The storage point is inserted by putting a SAVEPOINT command in the transaction. The syntax of this command is: SAVEPOINT saves the point name, if the storage point name is not given in the ROLLBACK statement, the entire transaction is rolled back.
  14. How to set the size of network data packets
    Generally, you can refer to the following methods to set the size of network data packets. If the application often performs bulk copy operations or sends and receives large amounts of text and image data, you can set this value to a larger value. If the amount of information received and sent by the application is small, you can set it to 512 bytes.
  15. Your understanding of cursors, the classification of cursors?
    The cursor is a pointer in the result set data, and its function is to store the result of each record when traversing the result set. Cursors are divided into explicit cursors and implicit cursors.
  16. Can COMMIT be used
    in triggers and why? Transaction control statements such as COMMIT cannot be used in triggers. Because the trigger is triggered by a transaction, if there is a transaction control statement, it will affect the transaction that triggered it. That is, the completed and uncommitted statements before the statement that triggered it will be affected. This will affect the consistency of the data

Guess you like

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