删除数据库 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. 3D分析之3D要素工具箱(转)

    来自:http://blog.csdn.net/kikitamoon/article/details/8193764 整理有关 ArcGIS 10.1 3D分析工具箱中,3D Feature 工具箱中 ...

  2. MySql安装步骤详解,MySql的root密码设置,启动MySql服务。

    1.下载mysql安装包,并解压,双击mysql-5.6.24-winx64.msi 2.点击下一步 3.选择custom 4.选择安装内容和位置,5个安装内容要选择will be installed ...

  3. iptables配置说明

    1.iptables的发展:  对于TCP/IP的七层模型来讲,我们知道第三层是网络层,三层的防火墙会在这层对源地址和目标地址进行检测.iptables是网络层的防火墙.   iptables的前身叫 ...

  4. 关于Arrays类总结

    Arrays是java中的工具类,其中所有的方法都是static.类名就可以直接调用其中的方法. 本文部分引用自: http://www.importnew.com/8952.html Arrays. ...

  5. 【转】周末班LR笔记总结—新手入门必备

    本来想上传文件的,上传半天没反应,只有这样了,图片不知道能显示不. 上午 学到2012.1.13 七天课 第一天(入门)二.三.四天(VUGEN脚本) 五天(Controller)六天(Analyse ...

  6. android之手动安装apk到模拟器

    一.将apk放到SDK的指定路径 二.打开命令行 三.安装apk到模拟器 此处遇到无法找到主机,解决办法: 发现是进程2512堵塞导致的 进入powershell 查看进程 发现2512进程是360手 ...

  7. git subtree

    语法:git subtree split -P <被裁减的目录> -b <分支> git subtree split -P SDK/CustomUI(需要裁减的) -b Cus ...

  8. and or判别

    and 和 or涉及到短路运算,python把0,'',none看做false,其余是true, 对于a and b,若a是true则,返回b,若a是false则返回a(因为a是true还需要判断b, ...

  9. WPF 中,如何使用自定义的resources

    第一步,先自己自定义一个Resources 1.新建一个xaml文件,在其中自定义好自己的Resources 这个Resource 的根节点是 <ResourceDictionary xmlns ...

  10. springmvc学习(二)——使用RequestMapper请求映射

    本次内容是@RequestMapping,后面会有实例代码 Spring MVC 使用 @RequestMapping 注解为控制器指定可以处理哪些 URL 请求在控制器的类定义及方法定义处都可标注@ ...