删除数据库 drop database database-name

创建新表格

  • create table tablename (col1 type1 [not null] [primary key], col2 type2 [not null], ...)
  • select top 0 * into tablenew from tableold or select * into b from a where 1<>1 - copy the schema without data
  • select * into tablenew from tableold or insert into b(a,b,c) select d,e,f from b - copy the schema with data

增加一列 alter tablename add columnname type

设置主键 alert tablename add primary key (columnname)

创建视图 create view viewname select statement

删除视图 drop view viewname

选择 select * from tablename where criteria

select a,b,c from tablename where a in (select d from tableb) or select a,b,c from tablename where a in (1,2,3)

select a.title, a.username, b.adddate from tablea, (select max(adddate) adddate from table where table.title=a.title) b

select * from tablename where a [not] in (value1, value2, value3...)

select top 10 * from tablename

插入 insert into tablename(col1, col2, ...) values (value1, value2, ...)

更新 update tablename set col1=value1 where criteria

查找 select * from tablename where col1 like '%value1%'

排序 select * from tablename order by col1, col2 [desc] ASC 升序,DESC降序

总数 select count(*) as totalcount from tablename

求和 select sum(col1) as sumvalue from tablename

平均 select avg(col1) as avgvalue from tablename

最大 select max(col1) as maxvalue from tablename

最小 select min(col1) as minvalue from tablename

between

select * from tablename where time between a and b

select * from tablename where time not between a and b

删除主表中已经在副表中没有的信息

delete from table1 where not exists (select * from table2 where table1,field1=table2.field2)

自增列

Create table Northwind
(CategoryID int identity(1,1) not null primary key,
 CategoryName Nvarchar not null,
 Description NvarChar not null,
 Picture nvarchar)

<一> SQL 基础的更多相关文章

  1. <三> SQL 基础

    SQL查询的一般形式,以及被逻辑处理的顺序 (8) select (9) distinct (11) <TOP_specification> <select_list> (1) ...

  2. [SQL] SQL 基础知识梳理(三) - 聚合和排序

    SQL 基础知识梳理(三) - 聚合和排序 [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/5926689.html 序 这是<SQL 基础知识梳理 ...

  3. Oracle知识梳理(三)操作篇:SQL基础操作汇总

    Oracle知识梳理(三)操作篇:SQL基础操作汇总 一.表操作 1.表的创建(CREATE TABLE): 基本语句格式:       CREATE TABLE  table_name ( col_ ...

  4. ASP.NET实现二维码 ASP.Net上传文件 SQL基础语法 C# 动态创建数据库三(MySQL) Net Core 实现谷歌翻译ApI 免费版 C#发布和调试WebService ajax调用WebService实现数据库操作 C# 实体类转json数据过滤掉字段为null的字段

    ASP.NET实现二维码 using System;using System.Collections.Generic;using System.Drawing;using System.Linq;us ...

  5. 数据库整理(三) SQL基础

    数据库整理(三) SQL基础 SQL语言的特点 集数据定义语言(DDL),数据操纵语言(DML),数据控制语言(DCL)功能于一体. 可以独立完成数据库生命周期中的全部活动: ​ ●定义和修改.删除关 ...

  6. 第三章 - SQL基础及元数据获取

    SQL的介绍 SQL的定义:结构化查询语句 SQL的作用:对库和表进行操作 SQL的常用分类 DDL 数据定义语言(Data Definition Language) DCL 数据控制语言(Data ...

  7. [SQL] SQL 基础知识梳理(一)- 数据库与 SQL

    SQL 基础知识梳理(一)- 数据库与 SQL [博主]反骨仔 [原文地址]http://www.cnblogs.com/liqingwen/p/5902856.html 目录 What's 数据库 ...

  8. [SQL] SQL 基础知识梳理(二) - 查询基础

    SQL 基础知识梳理(二) - 查询基础 [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/5904824.html 序 这是<SQL 基础知识梳理( ...

  9. [SQL] SQL 基础知识梳理(四) - 数据更新

    SQL 基础知识梳理(四) - 数据更新 [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/5929786.html 序 这是<SQL 基础知识梳理( ...

  10. [SQL] SQL 基础知识梳理(五) - 复杂查询

    SQL 基础知识梳理(五) - 复杂查询 [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/5939796.html 序 这是<SQL 基础知识梳理( ...

随机推荐

  1. 三个案例带你看懂LayoutInflater中inflate方法两个参数和三个参数的区别

    关于inflate参数问题,我想很多人多多少少都了解一点,网上也有很多关于这方面介绍的文章,但是枯燥的理论或者翻译让很多小伙伴看完之后还是一脸懵逼,so,我今天想通过三个案例来让小伙伴彻底的搞清楚这个 ...

  2. Divide and conquer method

    分治法是最广泛使用的算法设计方法之一,其基本思想:把大问题分解成一些较小的问题,然后由小问题的解方便地构造出大问题的解. 分治法说穿了就是把问题放小,如果被分的问题还是比较大,那么久继续分下去.为了能 ...

  3. 在centos 64bit 系统中安装使用WPS office的方法

    1. 安装32位开发库: yum install xulrunner.i686 yum install libXtst.i686 2. 在官网下载 wps-office-8.1.0.3724-0.1. ...

  4. PHP中长连接的实现

    最近遇到PHP程序在执行大量数据的时候提示超时,于是用到了set_time_limit()函数来设置PHP页面的最大运行时间. 设置允许脚本运行的秒数.如果这是默认的,该脚本返回一个致命的错误.默认限 ...

  5. Android沉浸式状态栏实现

    Step1:状态栏与导航栏半透明化 方法一:继承主题特定主题 在Android API 19以上可以使用****.TranslucentDecor***有关的主题,自带相应半透明效果 例如: < ...

  6. ios推送基于YII第三方组件的类库

    <?php namespace common\extensions\push; use \CComponent; /** * @desc iphone推送的接口程序 */ class ApnsP ...

  7. 【MySQL】MySQL中针对大数据量常用技术_创建索引+缓存配置+分库分表+子查询优化(转载)

    原文地址:http://blog.csdn.net/zwan0518/article/details/11972853 目录(?)[-] 一查询优化 1创建索引 2缓存的配置 3slow_query_ ...

  8. 经历:如何设置jquery easyui中下拉框不可编辑

    今天,在项目中碰到一个这样的问题,当选择按钮时候,查询条件是可以输入的,否则,表单框是不可用的[图1].但是,批量查询中的船名和装港用到了自动配置,即jquery-easyui中的combox的配置. ...

  9. 第六篇、git常用的命令

    1.oscine git服务器地址 https://git.oschina.net/ 2.帐号:18775134221@163.com 密码:562011 3.创建私有的仓库 4.使用命令 4.1 配 ...

  10. eclipse4.2.1插件安装(二)之Eclipse HTML Editor

    编辑一些页面文件,例如JSP,HTML,JS等,直接用内置的文本编辑器基本比较疯狂,自己选了一个顺手的编辑器,Eclipse HTML Editor! Eclipse HTML编辑器插件主要提供以下功 ...