SQL基本命令

基础

  • SELECT
    [DISTINCT] column_name
    [TOP number|percent column_name(s)]
    [AS alias_name_for_column]
    FROM table_name
    [
    WHERE column_name
    [operator value]
    [AND column_name operator value ] [OR column_name operator value ]
    [LIKE pattern]
    [IN (value1,value2,…)]
    [BETWEEN value1 AND value2]
    ]
    [AS alias_name_for_table]
    [ORDER BY column_name ASC|DESC] ;

  • DISTINCT: 不重复

  • TOP: 选择少数记录

  • INSERT INTO table_name [(column1,column2,column3,…)]
    VALUES (value1,value2,value3,…) ;

  • UPDATE table_name
    SET column1=value1,column2=value2,…
    WHERE some_column=some_value;

  • DELETE FROM table_name
    WHERE some_column=some_value;

pattern

  • ‘%’ 代表任意数量任意字符
  • ‘-‘ 代表单个字符
  • ‘[char]’ 代表方括号内任意字符
  • ‘[!char]’ or ‘[^char]’ 代表不存在方括号内任意字符
  • eg. SELECT * FROM Customers WHERE City LIKE '[a-c]%';

join

  • SELECT column_name(s)
    FROM table1
    INNER|LEFT|RIGHT|OUTER JOIN table2
    ON table1.column_name=table2.column_name;

misc

  • union 合并两个select的结果,不显示duplicate的结果
  • union all 合并两个select的结果,显示duplicate的结果
  • select into from 从现有表创建新表
  • insert into select from 插入表
    原文作者:crf1028
    原文地址: https://www.jianshu.com/p/b3f0b1c4fb2d
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞