• Python 学习笔记:Basic SQL


    这里主要是整理 SQL 一些基础的“增删查改”的语法,方便自己不记得的时候可以快速查找。

    SELECT Statement


    /* general syntax */
    SELECT column1, column2, ... FROM table1;
    
    /* retrieve all columns */
    SELECT * FROM table1;
    
    /* filter result or get specific data */
    SELECT * FROM table1 WHERE condition;
    
    /* retrieve the number of rows */
    SELECT COUNT(*) FROM table1;
    
    /* retrieve the number of some values */
    SELECT COUNT(column1) FROM table1 WHERE condition;
    
    /* retrieve some values without repeated items */
    SELECT DISTINCT column1 FROM table1;
    
    /* retrieve the number of some values without repeated items */
    SELECT COUNT(DISTINCT column1) FROM table1 WHERE condition;
    
    /* retrieve the first n rows from the table */
    SELECT * FROM table1 LIMIT n;
    
    /* retrieve the first n rows from the table starting from row m */
    SELECT * FROM table1 LIMIT n OFFSET m;
    

    INSERT, UPDATE, DELETE Statement


    /* general syntax */
    
    INSERT INTO table1 (column1, column2, ...) VALUES (value1, value2, ... );
    
    UPDATE table1 SET column1 = value1, column2 = value2, ... WHERE condition;
    
    DELETE FROM table1 WHERE condition;
    

    CREATE Statement


    /* general syntax */
    CREATE TABLE table1 (column1 datatype, column2 datatype, column3 datatype, ...);
    

    ALTER Statement


    /* add column */
    ALTER TABLE table1 ADD COLUMN column1 datatype constraint;
    
    /* delete column */
    ALTER TABLE table1 DROP COLUMN column1;
    
    /* change column data type */
    ALTER TABLE table1 ALTER COLUMN column1 SET DATA TYPE datatype
    
    /* rename column */
    ALTER TABLE table1 RENAME COLUMN name1 TO name2;
    

    TRUNCATE, DROP Statement


    /* clear table */
    TRUNCATE TABLE table1;
    
    /* delete table */
    DROP TABLE table1;
    
    作者:Yuki
    本文版权归作者和博客园所有,欢迎转载,转载请标明出处(附上博客链接)。 如果您觉得本篇博文对您有所收获,请点击右下角的 [推荐],谢谢!

    关注我的公众号,不定期更新学习心得
  • 相关阅读:
    java 静态方法分析
    编译时常量与运行时常量
    springboot+elasticsearch配置实现
    spring+mybatise注解实现
    @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
    @RequestBody 的正确使用办法
    springboot+jps+druid项目搭建
    python 源码安装
    liunx 时间ntp同步服务器
    spring 定时任务corn表达式
  • 原文地址:https://www.cnblogs.com/yukiwu/p/15656506.html
Copyright © 2020-2023  润新知