use tempdb;
if object_id('dbo.orders', 'U') is not null
drop table dbo.orders;
go
create table dbo.orders
(orderid int not null
constraint PK_Orders primary key,
orderdate date not null
constraint dft_orderdate default(current_timestamp),
empid int not null,
custid varchar(10) not null
);
insert into dbo.orders(orderid, orderdate, empid, custid)
values
(1001, '20090212', 3, 'A');
insert into dbo.orders(orderid, empid, custid)
values
(1002, 3, 'B');
insert into dbo.orders(orderid, orderdate, empid, custid)
values
(1003, '20090213', 4, 'B'),
(1004, '20090214', 1, 'A'),
(1005, '20090215', 1, 'C'),
(1006, '20090215', 3, 'C');
select * from
(values
(1003, '20090213', 4, 'B'),
(1004, '20090214', 1, 'A'),
(1005, '20090215', 1, 'C'),
(1006, '20090215', 3, 'C'))
as o(orderid, orderdate, empid, custid);
use tempdb;
insert into dbo.orders(orderid, orderdate, empid, custid)
select orderid, orderdate, empid, custid
from tsql2012.sales.orders
where shipcountry = 'UK';
insert into dbo.orders(orderid, orderdate, empid, custid)
select 10007, '20090215', 2, 'B' union all
select 10008, '20090215', 1, 'C' union all
select 10009, '20090216', 2, 'C' union all
select 10010, '20090216', 3, 'A';
use tsql2012;
if object_id('Sales.usp_getorders', 'P') is not null
drop proc sales.usp_getorders;
go
create proc sales.usp_getorders
@country as nvarchar(40)
as
select orderid, orderdate, empid, custid
from sales.orders
where shipcountry = @country;
go
use tempdb;
insert into dbo.orders(orderid, orderdate, empid, custid)
exec tsql2012.sales.usp_getorders @country = 'France';
use tempdb;
if object_id('dbo.orders', 'U') is not null
drop table dbo.orders;
select orderid, orderdate, empid, custid
into dbo.orders
from tsql2012.sales.orders;
use tempdb;
if object_id('dbo.locations', 'U') is not null
drop table dbo.locations
select country, region, city
into dbo.locations
from tsql2012.sales.customers
except
select country, region, city
from tsql2012.hr.employees;
use tempdb;
if object_id('dbo.t1', 'U') is not null
drop table dbo.t1;
create table dbo.t1
(
keycol int not null identity(1,1)
constraint PK_K1 primary key,
datacol varchar(10) not null
constraint chk_t1_datacol check(datacol like '[A-Za-z]%'));
insert into dbo.t1 values('A');
declare @new_key as int;
set @new_key = scope_identity();
select @new_key as new_key;
use tempdb;
if object_id('dbo.orders', 'U') is not null
drop table.dbo.orders;
if object_id('dbo.customers', 'U') is not null
drop table dbo.customers;
select * into dbo.orders from tsql2012.sales.orders;
select * into dbo.customers from tsql2012.sales.customers;
alter table dbo.customers add
constraint PK_Customers primary key(custid);
alter table dbo.orders add
constraint PK_Orders primary key(orderid);
alter table dbo.orders add
constraint FK_Orders foreign key(custid)
references dbo.customers(custid);
use tempdb;
delete from dbo.orders
where orderdate < '20070101';
use tempdb;
delete from o
from dbo.orders as o
join dbo.customers as c
on o.custid = c.custid
where c.country = N'USA';
delete from dbo.orders
where exists
(select * from dbo.customers as c
where orders.custid = c.custid
and c.country = 'USA');
use tempdb;
if object_id('dbo.orderdetails', 'U') is not null
drop table dbo.orderdetails;
if object_id('dbo.orders', 'U') is not null
drop table dbo.orders;
select * into dbo.orders from tsql2012.sales.orders;
select * into dbo.orderdetails from tsql2012.sales.orderdetails;
alter table dbo.orders add
constraint pk_orders primary key(orderid);
alter table dbo.orderdetails add
constraint pk_orderdetails primary key(orderid, productid),
constraint fk_orderdetails foreign key(orderid)
references dbo.orders(orderid);
use tempdb;
update dbo.orderdetails
set discount = discount + 0.05
where productid = 51;
update od
set discount = discount + 0.05
from dbo.orderdetails as od
join dbo.orders as o
on od.orderid = o.orderid
where custid = 1;
update dbo.orderdetails
set discount = discount + 0.05
where exists
(select * from dbo.orders as o
where o.orderid = orderdetails.orderid
and custid = 1);
use tempdb;
if object_id('dbo.sequence', 'U') IS NOT NULL
DROP TABLE DBO.sequence;
create table dbo.sequence
(val int not null);
insert into dbo.sequence values(0);
declare @nextval as int;
update dbo.sequence set @nextval = val + 1;
select @nextval;
use tempdb;
update od
set discount = discount + 0.05
from dbo.orderdetails as od
join dbo.orders as o
on o.orderid = od.orderid
where custid = 1;
with c as
(select custid, od.orderid, productid, discount, discount + 0.05 as newdiscount
from dbo.orderdetails as od
join dbo.orders as o
on od.orderid = o.orderid
where custid = 1
)update c set discount = newdiscount;
update d
set discount = newdiscount
from (select custid, od.orderid, productid, discount, discount + 0.05 as newdiscount
from dbo.orderdetails as od
join dbo.orders as o
on od.orderid = o.orderid
where custid = 1) as d;
use tempdb;
if object_id('dbo.t1', 'U') is not null
drop table dbo.t1;
create table dbo.t1(col1 int, col2 int);
go
insert into dbo.t1(col1) values(10);
insert into dbo.t1(col1) values(20);
insert into dbo.t1(col1) values(30);
select * from dbo.t1;
with c as
(select col1, col2,row_number() over(order by col1) as rownum
from dbo.t1 as t)
update c
set col2 = c.rownum;
use tempdb;
if object_id('dbo.orderdetails', 'U') is not null
drop table dbo.orderdetails;
if object_id('dbo.orders', 'U') is not null
drop table dbo.orders;
select * into dbo.orders from tsql2012.sales.orders;
delete top(50) from dbo.orders;
update top(50) dbo.orders
set freight = freight + 10.00;
with c as
(select top(50) * from dbo.orders
order by orderid)
delete from c;
with c as
(select top(50) *
from dbo.orders
order by orderid desc)
update c set freight = freight + 10.00;
use tempdb;
if object_id('dbo.t1', 'U') is not null
drop table dbo.t1;
create table dbo.t1
(keycol int not null identity(1,1)
constraint pk_t1 primary key,
datacol nvarchar(50) not null);
insert into dbo.t1(datacol)
output inserted.keycol, inserted.datacol
select lastname
from tsql2012.hr.employees
where country = N'USA';
declare @newrows table(keycol int, datacol nvarchar(40));
insert into dbo.t1(datacol)
output inserted.keycol, inserted.datacol
into @newrows
select lastname
from tsql2012.hr.employees
where country = N'UK';
select * from @newrows;
use tempdb;
if object_id('dbo.orders', 'U') is not null
drop table dbo.orders;
select * into dbo.orders from tsql2012.sales.orders;
delete from dbo.orders
output
deleted.orderid,
deleted.orderdate,
deleted.empid,
deleted.custid
where orderdate < '20080101';
分享到:
相关推荐
11.3 数据分析报告范例 第11章-数据分析报告简介全文共10页,当前为第8页。 通过前面知识的学习,相信读者朋友已经掌握了数据分析报告编写原则、流程以及结构等相关操作。 大神支招 01:撰写报告的注意事项 数据...
第8章 网络安全 数据通信与网络技术-第8章-网络安全全文共53页,当前为第1页。 本章提要 网络安全概述 网络安全标准和等级 防火墙技术(重点) 计算机病毒防范技术(重点) 数据通信与网络技术-第8章-网络安全全文共...
包含数据分析和数据挖掘的学习代码和实战代码 本项目很多内容属于边学边试。参考了书籍,但是很多代码存在过时和错误均被我修改。 数据挖掘是最近几年才出现的一个名词,其归根到底的目的就是经过一系列手段处理...
第8章 数据分组与汇总 第9章 多表联接 第10章 子查询 第11章 修改数据 第12章 全文索引查询 第13章 规划索引 第14章 创建和维护索引 第15章 实现视图 第16章 实现存储过程 第17章 实现用户定义函数 第18章 实现...
第15章 数据仓库及其应用 2 15.1数据仓库发展的由来 2 15.2数据仓库的概念 3 15.3 数据仓库体系结构 5 15.3.1 数据仓库的概念结构 5 15.3.2 数据仓库的层次结构 6 15.4 ETL 8 15.5 数据集市及其结构 10 15.6 元数据 ...
第8章 zookeeper的leader节点选择 31 第9章 zookeeper安装 33 第10章 zookeeper 命令行接口 35 第11章 zookeeper应用程序接口 39 第12章 zookeeper应用 40 第三部分 KAFKA学习 48 第12章 KAFKA介绍 49 12.1 KAFKA...
第1章 初识Python程序 目录 /CONTENTS 第2章 程序基本构成 第3章 控制结构 第4章 函数 第5章 复合数据类型 第6章 文件操作 第7章 数据可视化 第8章 图像处理 Python程序设计第6章+文件操作全文共44页,当前为第2页...
中文名: 数据结构实验教程 作者: 张凤琴图书分类: 软件 资源格式: PDF 版本: 扫描版 出版社: 北方交通大学出版社书号: ISBN:7810827820发行时间: 2006年06月 地区: 大陆 ...第八章 排序 第九章 文件
顺序查找,折半查找,散列表。。。面向对象数据结构(c++版)姜麟主编--------第8章 查找。书中错误已经修改过来,错误实在比较多。。
第8章 数据修改 8.1 插入数据 8.2 删除数据 8.3 更新数据 8.4 合并数据 8.5 通过表表达式修改数据 8.6 带有TOP选项的数据更新 8.7 OUTPUT子句 8.8 总结 8.9 练习 8.10 解决方案 第9章 事务和...
数据嗅探防范方式 数据嗅探防范方式 Internet 服务器 主机 验证、反嗅探工具 加密 数据嗅探防范方式主要有:验证、改变网络结构、反嗅探工具、加密 课件-第8章-网络安全全文共59页,当前为第12页。 非法使用 非法...
第8章 数据修改 8.1 插入数据 8.2 删除数据 8.3 更新数据 8.4 合并数据 8.5 通过表表达式修改数据 8.6 带有TOP选项的数据更新 8.7 OUTPUT子句 8.8 总结 8.9 练习 8.10 解决方案 第9...
第8章 连接查询与集合查询 第9章 子查询 第10章 常用函数 第11章 视图的创建与维护 第12章 插入数据记录 第13章 修改数据记录 第14章 删除数据记录 第15章 权限的授予与回收 第16章 事务的控制与管理 第17章 PLSQL...
第8章 数据库技术 8.1 连接数据库 实例264 使用ODBC DSN连接SQL Server数据库 实例265 用ADO动态连接数据库 8.2 添加数据 实例266 利用INSERT语句批量插入数据 实例267 利用SELECT INTO生成临时表 8.3 更新数据 实例...
第8章 二叉树 为什么使用二叉树? 树的术语 一个类比 二叉搜索树如何工作 查找节点 插入一个节点 遍历树 查找最大值和最小值 删除节点 二叉树的效率 用数组表示树 重复关键字 完整的tree.java程序 ...
第8章 项目ExTest,修改系统菜单的相关操作; 项目ExPdMenu,添加下拉菜单并实现命令响应,以及工具栏和状态栏的操作; 项目ExPuMenu,弹出菜单的创建、载入与功能实现; 项目ExMyDT,菜单、工具栏、状态栏综合操作...
第8章 与其他人共享数据透视表 175 8.1 与其他版本的Office共享数据透视表 175 8.1.1 Excel 2003数据透视表中不可用的功能 176 8.1.2 Excel 2007的兼容模式 176 8.1.3 版本为12的数据透视表没有降级方法 ...
第1章 系统简介 5 1.1 系统概述 5 1.2 系统目标 5 1.3 适用范围 5 1.4 系统特点 5 第2章 软件安装及产品获得 8 2.1 运行环境 8 2.2 数据库配置 8 ... 第8章 销售分析 37 8.1 月销售分析 37
第8章 自定义部件 第三部分 高级报表 第9章 处理多个数据表 第10章 数据源和数据库专家 第11章 在水晶报表中使用SQL 第12章 可视化分析数据 第13章 报表模版 第14章 报表引擎处理模型 。。。。。
第八章:增量爬虫。 第九章:验证码识别。 第十章 MongoDB 数据库。 第十一章 爬虫项目。 第十二章:Redis 数据库。 第十三章:分布式爬虫 Scrapy-redis 框架。 第十四章:Python 爬虫监控,自定义爬虫。 第十五章:...