Views and indexes (databases learning)

After that time SQL server database for the exam, it took me two weeks to read the whole book, which was made of notes (the teacher is zoned for emphasis), Java now learning to do several projects, there are many things not found In particular understanding, specially go over again, thinking and rethinking their own, are interested can look at GitHub article

1. understand what a view. Advantage of the view.

Introduction - basic table in the database is a database designer point of view in accordance with the design does not necessarily meet the needs of all users.

SQL Server can redefine the data structure of the table according to user needs, this data structure is a view (external user mode)

View: YES (mode) lead out from one or several basic Table, is a virtual table, it does not denote any physical data.

(Database stores only the view definition, does not store data corresponding to the view, and also modify the data base table through view)

View advantages:

         - |: users with centralized data, simplify the user's query and data processing.

         - |: to ensure data logic independence .

         - |: re-customization data so easy to share; merge segmentation data, it is conducive to the output data into the application.

         - |: data privacy.

2. The view of creation, modification, use, delete

See test report

Founding principles: the current database, identifiers must follow the rules, you can create a view on top of other views, if a view as (arithmetic expressions, or constants derived from the built-in function, the user needs to specify the name of its characteristics)

Using (insert, update, delete) data base view table modification, the update condition may be fulfilled:

         - |: only reference column of a base table. When a multi-view dependency table, data insertion and deletion can not view, modify only one table data.

         - |: View modified columns must directly reference the data base (non-polymeric function, calculation, set operations) listed in

         - |: column should not be modified by the group by the time you create a view, having, distinct, affect the top statement.

Create (create view view name as a query)

Modify (alter view view name as a query)

Use (select * from view name), with a similar database queries

Delete (drop view view name)

3. What is the index. Classification index. What issues should consider creating an index?

Index (index): the value is the structure of the database table or a plurality of columns to sort, its main purpose is to improve the performance of the SQL Server system, data query speed. (Pointing to the base table record by record key values ​​in the table)

According organized into :( there is a maximum of 250)

         - |: clustered index, the table data will be physically sorted. (Only one, when the primary key constraint defined, with the main building automatically build the index as a polymerization column)

         - |: non-clustered index, the data in the table will not be physical sort. (Directory purely directory, the text is purely text)

Issues to consider when creating an index

         - |: to build a large number of indexes on a table, it is governed by a tradeoff. (Less frequently updated index, updated little more than a large amount of data index).

         - |: a small table on the index may not produce optimal performance.

         - |: for primary and foreign key columns should consider indexing. (Primary query key, foreign key connection)

         - |: columns and values ​​are rarely used in the query should not consider building a small column index.

         - |: If the view contains an aggregate function, or connections, to create a view index can significantly improve query performance.

4. How to create an index, the index view information, delete indexes

Create (create index index name on the base table (column name))

         - |: created indirectly (defining or modifying the table structure table structure, defines the primary key constraint (pramary key) generated automatically clustered index, uniqueness constraint (UNIQUE) unique non-clustered index.

         - |: Creating Indexed Views

View index (exec stored procedures (sp_helpindex or sp_help) Basic Table)

Remove the index (drop index base table. Index name)

         - |: must be deleted table constraints (primary key, unique), you can remove the constraints. (Automatically generated according to the constraint index)

         - |: When you delete a table, automatically delete the index on this table.

Guess you like

Origin blog.csdn.net/weixin_43126117/article/details/90759188