Learning of SQL_sql language

relational database SQL

sql basic functions

SQLde basic concepts

  • Main knowledge points

    1. The outer schema contains several views and some basic tables
    2. The schema contains several basic tables
    3. The inner schema contains several storage files
    4 Operation objects

    Basic table: a table that exists independently, a relationship corresponds to a basic table

    View : Only the definition of the view is stored in the database, and the data corresponding to the view is not stored

    CREATE VIEW view_name AS
    SELECT column_name(s)
    FROM table_name
    WHERE condition

    Index :

    CREATE INDEX indexName ON mytable(username(length));

    5. Define the schema

    `create schema<模式名> authorization<用户名>`

    6. Delete mode:

    drop schema<模式名> <cascade|restric>
    cascade: cascade, which means that all database objects in the schema are deleted when the schema is deleted;
    restrict: restriction, which means that the subordinate database objects (such as tables, views) have been defined in the schema, and the deletion statement is rejected. implement

    7. Definition, deletion and modification of basic tables
    1. Creating a schema establishes a database namespace Each frame, the first thing to define in this frame is the basic database tables contained in the schema.
    Create a table:

        Create table Student(
        Sno char(9) primary key,
        Sname char(20) unique,
        Ssex char(2)),
        Foreign key(sno) reference SC(Sno), --注意表级约束条件与行级约束条件

    2. Modify the basic table

    Alter table <表名>  
    [add [column]<新列名><数据类型>  
    [drop [column]<列名><cascade|restric>

    3. Delete the base table

        `Drop table <表名>[cascade|restric]`

    The base table to be dropped cannot be referenced by constraints on other tables

    8. Data query

    select select_list
    [into new_table_name]
    from table_source
    [where search_conditions]
    [group by group_by_expression]
    [having search_conditions]
    [order by order_expression [ASC|DESC]]

    9. Character matching
    %: represents any length a%b
    (underscore) represents a single character a_b If it exists, use _ instead
    . If the matching character after like does not contain wildcards, you can use =

    10.Order by: Sort the search results in ascending or descending order of one or more attribute columns

    11. Aggregate function
    count(*): count the number of tuples
    count(<column name>): count the number of values ​​in a column
    sum, avg, max, min When the aggregate function encounters a null value, it skips non-null values value, and only deal with null values
    ​​where clause cannot use aggregate function as conditional expression

    12.group by: Group the query results by the values ​​of one or more columns, and the values ​​are equal to a group

    13.The difference between where and having is the difference in the role of the object

    14. Join queries include

        等值连接查询:
        非等值连接查询:     嵌套循环连接算法的基本思想
            where S.sno = SC.sno
        自然连接查询:在等值连接中把目标列中重复的属性列去掉则为自然连接
        自身连接查询:查询每一门课的间接先修课
        外连接查询 :把悬浮元组保存在结果关系中
        复合条件查询:

    15. Nested query:
    the Select statement of the subquery cannot use the order by statement, and the order by can only sort the results
    16. Uncorrelated subquery: In
    correlated subquery (depending on a property value of the parent query): Exists: Subquery with exists predicate returns no results, only logical true values

    17. Collection operations:

    并操作:union  
    交操作:intersect  
    差操作:except  

    18. Query based on derived table: put the subquery in the from clause, you must specify an alias for the derived table

    Data Update

    1. Insert data
    2. Modify data:

    Update Student 
    set sage = 22,
    where sno =  '1213223'  

    3 Delete data

    delect from 表名 where <条件>

    Introduction to Database Systems

    4/22/2018 8:40:36 PM

Guess you like

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