SQL SERVER (1) database object

Table 1. The
    table is a database most used objects, each database is composed of several tables. Each database is a table of rows and columns, it is like common Ex cel form. In the database: the rows in the table are called records, and the columns are called fields. As shown in Table 1-1 is a student information table for storing student information.
                                                                          Table 1.1 Student Information Form

Numbering Surname Age    student ID Class
1 Zhang San 20  20001   A shift  
2 Li Si  21 20002   Second shift

    Here, the number, name, age, student number, class are all field names in the table, and the "1, Zhang San, 20, 20001, one class" is a record in the student information table.
2. The view
      view is also a table, usually view as a virtual table in the database, the data in the view are the data queried from the database table. In other words, all the data in the view comes from the tables that exist in the database. The tables that make up the view are also called base tables or source tables. The role of the 4 views in the database is to provide convenience for querying data and improve database security. Suppose there is a student information table and class information table, as shown in Table 1.2 and Table 1.3:
                                                                       Table 1.2 Student Information Table

 Numbering Surname  Class coding  
1 Zhang San 01
2 Li Si  02

                                                                              Table 1.3 Class Information Table

 Class coding Class name
01 A shift
02 Second shift

    If you want to get the student's name and the class name of the student, you must query the student information table and class information table to get it. This slows down the query. At this time, you can consider using the view to put the data to be queried into the view, as shown in Table 1.4. For the operation from table to view, it will be described in the following chapters.
                                                                  Table 1.4 Student Class Information View Table

 Numbering Surname Class name
1  Zhang Lan A shift
2  Li Wang Second shift

    In this way, when querying the student name and class information, you only need to query the view shown in Table 1.4. At this time, not only the query is convenient, but also the field information of the student information table and the class information table can be hidden, thereby improving the security of database operations.

3. Index The
    index is created on the field in the data table, which is equivalent to the book directory. Setting the index field in the table can improve the query speed. In the data table, the index is divided into two types of clustered index and non-clustered index, but the clustered index has only one column, then when retrieving the data in the table, they are also retrieved according to the clustered index.

4. Stored procedure
    Stored procedure is, literally, a process used to store data table operations. In fact, the stored procedure is indeed an object that stores the methods of operating on the data table together. Stored procedures, like views, can improve the security of the database. Through the stored procedures, operations such as adding, deleting, modifying, and querying data tables can be completed. Using stored procedures can also perform complex operations such as some judgments of data tables.
5. Trigger
    Trigger can be understood as executing a certain method when performing a certain operation. Triggers are one of the important database objects to ensure data consistency of data tables. Triggers can complete operations such as inserting data into one table while inserting data into another table, or deleting data in another table. However, use triggers with caution, because if there are a large number of triggers in the database, the efficiency of the database will be affected during operation.
 

发布了146 篇原创文章 · 获赞 0 · 访问量 2716

Guess you like

Origin blog.csdn.net/ngbshzhn/article/details/105666595