Partial understanding of database applications

6.30

Some learning experiences about database

 

1.Left Join.

    The query methods of multi-table join are divided into the following types: inner join, outer join and cross join. Outer joins are divided into: left outer join, right outer join and full outer join. For different query methods, using the same join algorithm will also have different costs. This is closely related to its implementation. It is necessary to consider how different query methods are implemented. The specific connection method used is determined by the optimizer. Determined by weighing the cost.

    left join (left join) returns including all records in the left table and records in the right table that are equal to the joined fields 

    right join (right join) returns including all records in the right table and the left table join fields are equal records
    inner join (equivalent join) returns only the two tables in the join fields are equal to the row.

 

    in the examples given. Query the loan situation of all banks in 2012, list the bank name, the number of loan companies, and the total loan amount

    Select Bname,count(distinct eno),sum(lamount)

    From bankt left join loant on loant.bno=bankt.bno

    Where year(ldate)=2012  

    Group by Bname

    After practice, it is found that the results are not correct.       

    Because the left join is used here, it is based on the left table bankt, and in the where selection condition, the age of the right table is limited. Here we must figure out that the base table is the left table, otherwise the result will be wrong.

    2.In and Exist

    Select * From LegalEntityT

    Where Eno

    in (Select Eno From loant where lamount>1000)

    Vs

    Select * From LegalEntityT

    Where Exists(

    Select Eno From loant where loant.Eno= LegalEntityT.Eno

 

        and lamount>1000)

    Among them, In - traverse all data, compare each element of the collection

    Exist - can be used in the case of indexing, block, and high efficiency.

 

    3. Stored procedure:

    Create proc[edure] stored procedure name

    [@parameter name data type[=default][OUTPUT]]

    WITH ENCRYPTION

    AS

    Begin

      TSQL statement

    END。

    ①Stored locally, can be bound to the identity, stored in memory, ignoring network efficiency and unreliability.

    ②All processes can be compiled, executed after compilation, and executed again with high efficiency

    ③ Modular, can be directly called and executed.

    ④Encryption can be done.

    ⑤ Can be used as professional code generation, import data conversion.

 

     4. Use of indexes

    a. The work of the index: depends on the corresponding data parameters in the physical execution plan

    b. Data scale: more than 5000 pieces of data can be considered to build an index, and the actual need to consider the growth trend of the data to design

    Oracal database should be considered for indexing when there are at least 10,000 entries;

    c. When to use the index: When the data is operated in batches, it is often necessary to temporarily remove the index, that is, delete the index and import the data and then generate the index,

    d. Products with high attention can be indexed

    The more indexes, the higher the maintenance cost during operation, which affects the efficiency of batch processing of the database.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326198921&siteId=291194637