<一> SQL 基础
删除数据库 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 基础的更多相关文章
- <三> SQL 基础
SQL查询的一般形式,以及被逻辑处理的顺序 (8) select (9) distinct (11) <TOP_specification> <select_list> (1) ...
- [SQL] SQL 基础知识梳理(三) - 聚合和排序
SQL 基础知识梳理(三) - 聚合和排序 [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/5926689.html 序 这是<SQL 基础知识梳理 ...
- Oracle知识梳理(三)操作篇:SQL基础操作汇总
Oracle知识梳理(三)操作篇:SQL基础操作汇总 一.表操作 1.表的创建(CREATE TABLE): 基本语句格式: CREATE TABLE table_name ( col_ ...
- 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 ...
- 数据库整理(三) SQL基础
数据库整理(三) SQL基础 SQL语言的特点 集数据定义语言(DDL),数据操纵语言(DML),数据控制语言(DCL)功能于一体. 可以独立完成数据库生命周期中的全部活动: ●定义和修改.删除关 ...
- 第三章 - SQL基础及元数据获取
SQL的介绍 SQL的定义:结构化查询语句 SQL的作用:对库和表进行操作 SQL的常用分类 DDL 数据定义语言(Data Definition Language) DCL 数据控制语言(Data ...
- [SQL] SQL 基础知识梳理(一)- 数据库与 SQL
SQL 基础知识梳理(一)- 数据库与 SQL [博主]反骨仔 [原文地址]http://www.cnblogs.com/liqingwen/p/5902856.html 目录 What's 数据库 ...
- [SQL] SQL 基础知识梳理(二) - 查询基础
SQL 基础知识梳理(二) - 查询基础 [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/5904824.html 序 这是<SQL 基础知识梳理( ...
- [SQL] SQL 基础知识梳理(四) - 数据更新
SQL 基础知识梳理(四) - 数据更新 [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/5929786.html 序 这是<SQL 基础知识梳理( ...
- [SQL] SQL 基础知识梳理(五) - 复杂查询
SQL 基础知识梳理(五) - 复杂查询 [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/5939796.html 序 这是<SQL 基础知识梳理( ...
随机推荐
- Linux上在同一端口上共享SSH与HTTPS的工具:SSLH
添加EPEL源 CentOS 6 # yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rp ...
- 通过样式调整input 中password text默认长度
原文出处 <input >标签内的type分别为password和text时其默认长度和宽度不一致,而在做登陆框时往往需要将它们的长度和宽度设置一致.如下的方法可以通过css控制使其一致: ...
- 外部div自适应内部标签的高度,设置最小高度、最大高度
一.div自适应高度:在前端开发中经常需要让外层的div自动适应内部标签和内容的高度,内部标签可能是<div>.<ul>.<ol>或者文字等各种内容.造成外层的di ...
- 【C#4.0图解教程】笔记(第19章~第25章)
第19章 泛型 1.泛型概念 泛型提供了一种更准确地使用有一种以上的类型的代码的方式. 泛型允许我们声明类型参数化的代码,我们可以用不同的类型进行实例化. 泛型不是类型,而是类型的模板. 2.声明 ...
- 简单测试IIS下的UrlRewrite技术
UrlRewrite即地址变换.它可以实现静态功能方便搜索引擎收录,比如http://***/news.asp?corangeid=11它可以变为htt://***/news-11.html.这样还实 ...
- Beyond Compare 相同文件对比结果仍显示红色 解决方案
转载:http://blog.sina.com.cn/s/blog_4d4bc1110100zj7x.html 1. 问题详细描述如下. 下图显示对比结果中,两侧的aaa.xml是一模一样,会话中 ...
- GWT环境搭建--eclipse
上面下来需求,需要用到GWT,以前没接触过,搭个开发环境研究研究 安装软件我放在百度云盘里了(其他版本自己找,我的版本 eclipse4.4 luna gwt2.7) 链接:http://pan.b ...
- SQL server 的约束条件【转】
SQLServer - 约束 一.约束的分类 在SQLServer中,有3种不同类型的约束. 1.实体约束 实体约束是关于行的,比如某一行出现的值就不允许出现在其他行,例如主键. 2.域约束 域约束是 ...
- PetaPoco更新记录方法
/// <summary> /// Performs an SQL update /// </summary> /// <param name="tableNa ...
- Linq 中的TakeWhile 和 SkipWhile
这两个概念容易搞混 理解了一番后 在这里写下便于记忆 SkipWhile 可以理解为如果条件满足 就一直跳过 知道不满足后 就取剩下的所有元素(后面的不会再判断) TakeWhile 可以理解为 ...