<一> 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 基础知识梳理( ...
随机推荐
- 深入理解Binder(一),从AIDL谈起
打算写一篇Binder介绍的文章,仔细想想一篇文章貌似很难厘清,于是我打算从AIDL入手,本篇先来简单介绍下AIDL的使用,然后在此基础上我们继续来研究Binder的工作原理.小伙伴们都知道,AIDL ...
- the first assignment of software testing
Github ID: bzdwdmzjsmff Github address: https://github.com/bzdwdmzjsmff alternative article: Increa ...
- [置顶] 运算符重载,浅拷贝(logical copy) ,vs, 深拷贝(physical copy),三大件(bigthree problem)
一般的我们喜欢这样对对象赋值: Person p1;Person p2=p1; classT object(another_object), or A a(b); classT object = ...
- 【排障】nginx在reload时候报错invalid PID number
nginx在reload时候报错invalid PID number nginx重新加载配置文件时候报错,提示无效的PID: 解决的办法有二: 第一种思路是因为是加载配置文件报的错,所以用-c 选项指 ...
- Linux 系统下原版 texlive 2016 的安装与配置
尽管大部分常见的linux系统的包管理器内都会包含texlive,然而最好还是安装TUG发布的原版texlive.这是由于:1,软件仓库内的texlive通常版本较陈旧:2,由于版权因素一些tex宏包 ...
- HP服务器RAID配置
公司服务器硬盘空间不够了(HP的服务器),购买了10块硬盘,由于之前没有做过RAID,感觉很高大上的样子,就请教了HP的技术人员,技术人员发了两份文档,分别是DL380G7(DL580G7)和DL38 ...
- TamperData火狐插件启用
今天第一次在准备学习sqlmap的时候看到有人使用了这个TamperData火狐的插件,所以我也安装来看看,光是安装了,但是重启浏览器之后不知道怎么启用,得不到想要的运行界面,所以在这里记录一下,为自 ...
- 关于Eclipse中的一些基本知识
Eclipse中寻找JRE的顺序是:vm参数指定的JRE--->elipse目录下的JRE--->操作系统中默认的JRE,利用这个特性也可以用vm参数来解决当本机安装有多个JRE的情况. ...
- Navicate DataModel 注册码
注册信息: 姓 名:ttrar.com 组 织:(空) 序列号:NAVD-6CLM-6BKA-5TXK 内容来自: 可视化数据库设计工具(Navicat Data Modeler)1.0. ...
- JDBC入门连接MySQL查数据
在MySQL中建立user表,插入数据 create table user( id int, name varchar(10), age int )engine myisam charset utf8 ...