- 浏览: 1768297 次
- 性别:
- 来自: 成都
文章分类
- 全部博客 (520)
- Oracle (10)
- Oracle错误集 (8)
- Oracle安装升级 (15)
- Oracle日常管理 (51)
- Oracle字符集 (7)
- Oracle备份恢复 (24)
- Oracle优化 (4)
- Oracle编程 (52)
- Oracle导入导出 (19)
- Oracle体系结构 (15)
- Oracle网络 (2)
- Oracle安全 (2)
- Oracle权限 (3)
- Oracle数据字典和性能视图 (2)
- Oracle常用地址 (5)
- SQLPLUS专栏 (7)
- SqlServer (13)
- SqlServer2005编程 (27)
- SqlServer2005管理 (15)
- MySQL (20)
- Dorado应用 (1)
- C# (24)
- Arcgis Server开发 (20)
- ArcSDE技术 (19)
- UML学习 (2)
- 设计模式 (2)
- JAVA EE (4)
- JavaScript (3)
- OFBIZ (27)
- JAVA WEB开发 (22)
- Linux&Unix (34)
- SHELL编程 (14)
- C语言 (11)
- 网络协议 (14)
- FREEMARKER (2)
- GROOVY (2)
- JAVA语言 (3)
- 防火墙 (0)
- PHP (2)
- Apache (2)
- Loader Runner (1)
- Nginx (3)
- 数据库理论 (2)
- maven (1)
最新评论
-
怼怼怼怼:
oracle的timestamp类型使用 -
怼怼怼怼:
oracle的timestamp类型使用 -
怼怼怼怼:
oracle的timestamp类型使用 -
pg_guo:
感谢
oracle中查看用户权限 -
xu234234:
5、MapResourceManager控件中添加了两个服务, ...
北京ArcGis Server应用基础培训笔记1
一、插入数据
包括:select into、insert exec、插入新行、带有output的insert、序列机制
1、select into
select into 语句不向调用者返回结果集,而是创建一个包含查询结果集的新表。新表的列沿用查询结果集的列名称、数据类型、可空性以及identity属性。select into 不从查询的源表复制约束、索引、触发器。如果你希望在表中包含与查询的源相同的索引、约束和触发器,你必须在执行完该语句以后再添加
如果源列包含identity属性,目标列中也会包含该属性.如果不想向目标列复制identity属性,对源列做些修改即可。
例如:OrderID+0 as OrderID
SELECT OrderID+0 AS OrderID, CustomerID, EmployeeID, OrderDate,
RequiredDate, ShippedDate, ShipVia, Freight, ShipName,
ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry
INTO dbo.MyOrders
FROM Northwind.dbo.Orders
WHERE 1 = 2;
GO
提示:假设你要把存储过程或动态批处理的结果集插入到新表,但又不知道它的架构。这时,你可以在select into 语句的from子句中指定openquery,并把自己的服务器看作是一个链接服务器:
exec sp_serveroption <your_server>,'data access',true;
select * into <target_table>
from openquery(<your_server>,'exec{<proc_name>|(<dynamic_batch>)}')
2、insert exec
insert into <target_table> exec{<proc_name>|(<dynamic_batch>)}
3、插入新行
此处只讨论从源表向目标表插入数据,但只筛选目标表不包含其键值得行
--方案一: Insert New Rows From StageCusts
INSERT INTO dbo.MyCustomers(CustomerID, CompanyName, ContactName,
ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax)
SELECT CustomerID, CompanyName, ContactName,
ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax
FROM dbo.StageCusts AS S
WHERE NOT EXISTS
(SELECT * FROM dbo.MyCustomers AS T
WHERE T.CustomerID = S.CustomerID);
--方案二: Insert New Customers From StageOrders using DISTINCT
INSERT INTO dbo.MyCustomers(CustomerID, CompanyName, ContactName,
ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax)
SELECT DISTINCT CustomerID, CompanyName, ContactName,
ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax
FROM dbo.StageOrders AS S
WHERE NOT EXISTS
(SELECT * FROM dbo.MyCustomers AS T
WHERE T.CustomerID = S.CustomerID);
--方案三: Insert New Customers From StageOrders using MIN
INSERT INTO dbo.MyCustomers(CustomerID, CompanyName, ContactName,
ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax)
SELECT CustomerID, CompanyName, ContactName,
ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax
FROM dbo.StageOrders AS S
WHERE NOT EXISTS
(SELECT * FROM dbo.MyCustomers AS T
WHERE T.CustomerID = S.CustomerID)
AND S.OrderID = (SELECT MIN(OrderID) FROM dbo.StageOrders AS S2
WHERE S2.CustomerID = S.CustomerID);
--方案四: Insert New Customers From StageOrders using Row Numbers
INSERT INTO dbo.MyCustomers(CustomerID, CompanyName, ContactName,
ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax)
SELECT CustomerID, CompanyName, ContactName,
ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax
FROM (SELECT
ROW_NUMBER() OVER(PARTITION BY CustomerID ORDER BY OrderID) AS rn,
CustomerID, CompanyName, ContactName, ContactTitle, Address, City,
Region, PostalCode, Country, Phone, Fax
FROM dbo.StageOrders) AS S
WHERE NOT EXISTS
(SELECT * FROM dbo.MyCustomers AS T
WHERE T.CustomerID = S.CustomerID)
AND rn = 1;
GO
4、带有output的insert
通过使用新的output子句,Sql Server 2005支持从数据修改语句中返回输出
例子:
IF OBJECT_ID('dbo.CustomersDim') IS NOT NULL
DROP TABLE dbo.CustomersDim;
GO
CREATE TABLE dbo.CustomersDim
(
KeyCol INT NOT NULL IDENTITY PRIMARY KEY,
CustomerID NCHAR(5) NOT NULL,
CompanyName NVARCHAR(40) NOT NULL,
/* ... other columns ... */
);
-- Insert New Customers and Get their Surrogate Keys
DECLARE @NewCusts TABLE
(
CustomerID NCHAR(5) NOT NULL PRIMARY KEY,
KeyCol INT NOT NULL UNIQUE
);
INSERT INTO dbo.CustomersDim(CustomerID, CompanyName)
OUTPUT inserted.CustomerID, inserted.KeyCol
INTO @NewCusts
--OUTPUT inserted.CustomerID, inserted.KeyCol
SELECT CustomerID, CompanyName
FROM Northwind.dbo.Customers
WHERE Country = N'UK';
SELECT CustomerID, KeyCol FROM @NewCusts;
GO
二、删除数据
1、truncate 和 delete
如果你要从表中移除所有行,应该使用truncate table,而不应该使用不带where子句的delete。delete总是被完整的记录到日志,而truncate table总是按最小方式被记录到日志
truncate table 和 delete 除了在性能方面有巨大差异外,它们对identity属性的处理方式也不同.truncate table 把identity属性重置为最初的种子,而delete则不会
2、移除包含重复数据的行
解决方案一:要求整行都重复
SELECT DISTINCT * INTO dbo.OrdersTmp FROM dbo.OrdersDups;
DROP TABLE dbo.OrdersDups;
EXEC sp_rename 'dbo.OrdersTmp', 'OrdersDups';
解决方案二:要求表中有唯一标识符
DELETE FROM dbo.OrdersDups
WHERE EXISTS
(SELECT *
FROM dbo.OrdersDups AS O2
WHERE O2.OrderID = dbo.OrdersDups.OrderID
AND O2.KeyCol > dbo.OrdersDups.KeyCol);
GO
解决方案三:要求表中有唯一标识符
SELECT O.OrderID, CustomerID, EmployeeID, OrderDate, RequiredDate,
ShippedDate, ShipVia, Freight, ShipName, ShipAddress, ShipCity,
ShipRegion, ShipPostalCode, ShipCountry
INTO dbo.OrdersTmp
FROM dbo.OrdersDups AS O
JOIN (SELECT OrderID, MAX(KeyCol) AS mx
FROM dbo.OrdersDups
GROUP BY OrderID) AS U
ON O.OrderID = U.OrderID
AND O.KeyCol = U.mx;
DROP TABLE dbo.OrdersDups;
EXEC sp_rename 'dbo.OrdersTmp', 'OrdersDups';
解决方案四:用cte和row_number函数实现一种快速的解决方案
WITH Dups AS
(
SELECT *,
ROW_NUMBER() OVER(PARTITION BY OrderID ORDER BY OrderID) AS rn
FROM dbo.OrdersDups
)
DELETE FROM Dups WHERE rn > 1;
GO
3、基于联接的delete
--非标准查询
BEGIN TRAN
DELETE FROM OD
FROM dbo.[Order Details] AS OD
JOIN dbo.Orders AS O
ON OD.OrderID = O.OrderID
WHERE O.OrderDate >= '19980506';
ROLLBACK TRAN
--标准查询
BEGIN TRAN
DELETE FROM dbo.[Order Details]
WHERE EXISTS
(SELECT *
FROM dbo.Orders AS O
WHERE O.OrderID = dbo.[Order Details].OrderID
AND O.OrderDate >= '19980506');
ROLLBACK TRAN
GO
4、带有output的delete
例子:
WHILE 1=1
BEGIN
BEGIN TRAN
DELETE TOP(5000) FROM dbo.LargeOrders
OUTPUT deleted.* INTO dbo.OrdersArchive
WHERE OrderDate < '20010101';
IF @@rowcount < 5000
BEGIN
COMMIT TRAN
BREAK;
END
COMMIT TRAN
END
GO
三、更新数据
1、基于联接的update
例子:
方案一:
UPDATE O
SET ShipCountry = C.Country,
ShipRegion = C.Region,
ShipCity = C.City
FROM dbo.Orders AS O
JOIN dbo.Customers AS C
ON O.CustomerID = C.CustomerID
WHERE C.Country = 'USA';
方案二:
WITH UPD_CTE AS
(
SELECT
O.ShipCountry AS set_Country, C.Country AS get_Country,
O.ShipRegion AS set_Region, C.Region AS get_Region,
O.ShipCity AS set_City, C.City AS get_City
FROM dbo.Orders AS O
JOIN dbo.Customers AS C
ON O.CustomerID = C.CustomerID
WHERE C.Country = 'USA'
)
UPDATE UPD_CTE
SET set_Country = get_Country,
set_Region = get_Country,
set_City = get_City;
2、select和update赋值语句
赋值select
如果表中没有记录则为null,如果有多条记录则为最后一跳记录的值
DECLARE @EmpID AS INT, @Pattern AS NVARCHAR(100);
SET @Pattern = N'Davolio'; -- Try also N'Ben-Gan', N'D%';
SET @EmpID = 999;
SET @EmpID = (SELECT EmployeeID
FROM dbo.Employees
WHERE LastName LIKE @Pattern);
SELECT @EmpID;
GO
赋值update
CREATE TABLE dbo.T1
(
col1 INT NOT NULL,
col2 VARCHAR(5) NOT NULL
);
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'A');
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'B');
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'C');
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'C');
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'C');
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'B');
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'A');
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'A');
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'C');
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'C');
go
方案一:
DECLARE @i AS INT;
SET @i = 0;
UPDATE dbo.T1 SET @i = col1 = @i + 1;
逻辑上,这个set语句等价于set col1=@i+1,@i=@i+1
在update语句中,你无法控制T1中的行被扫描和修改的顺序
GO
方案二:
-- SQL Server 2005
WITH T1RN AS
(
SELECT col1, ROW_NUMBER() OVER(ORDER BY col2) AS RowNum
FROM dbo.T1
)
UPDATE T1RN SET col1 = RowNum;
GO
包括:select into、insert exec、插入新行、带有output的insert、序列机制
1、select into
select into 语句不向调用者返回结果集,而是创建一个包含查询结果集的新表。新表的列沿用查询结果集的列名称、数据类型、可空性以及identity属性。select into 不从查询的源表复制约束、索引、触发器。如果你希望在表中包含与查询的源相同的索引、约束和触发器,你必须在执行完该语句以后再添加
如果源列包含identity属性,目标列中也会包含该属性.如果不想向目标列复制identity属性,对源列做些修改即可。
例如:OrderID+0 as OrderID
SELECT OrderID+0 AS OrderID, CustomerID, EmployeeID, OrderDate,
RequiredDate, ShippedDate, ShipVia, Freight, ShipName,
ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry
INTO dbo.MyOrders
FROM Northwind.dbo.Orders
WHERE 1 = 2;
GO
提示:假设你要把存储过程或动态批处理的结果集插入到新表,但又不知道它的架构。这时,你可以在select into 语句的from子句中指定openquery,并把自己的服务器看作是一个链接服务器:
exec sp_serveroption <your_server>,'data access',true;
select * into <target_table>
from openquery(<your_server>,'exec{<proc_name>|(<dynamic_batch>)}')
2、insert exec
insert into <target_table> exec{<proc_name>|(<dynamic_batch>)}
3、插入新行
此处只讨论从源表向目标表插入数据,但只筛选目标表不包含其键值得行
--方案一: Insert New Rows From StageCusts
INSERT INTO dbo.MyCustomers(CustomerID, CompanyName, ContactName,
ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax)
SELECT CustomerID, CompanyName, ContactName,
ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax
FROM dbo.StageCusts AS S
WHERE NOT EXISTS
(SELECT * FROM dbo.MyCustomers AS T
WHERE T.CustomerID = S.CustomerID);
--方案二: Insert New Customers From StageOrders using DISTINCT
INSERT INTO dbo.MyCustomers(CustomerID, CompanyName, ContactName,
ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax)
SELECT DISTINCT CustomerID, CompanyName, ContactName,
ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax
FROM dbo.StageOrders AS S
WHERE NOT EXISTS
(SELECT * FROM dbo.MyCustomers AS T
WHERE T.CustomerID = S.CustomerID);
--方案三: Insert New Customers From StageOrders using MIN
INSERT INTO dbo.MyCustomers(CustomerID, CompanyName, ContactName,
ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax)
SELECT CustomerID, CompanyName, ContactName,
ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax
FROM dbo.StageOrders AS S
WHERE NOT EXISTS
(SELECT * FROM dbo.MyCustomers AS T
WHERE T.CustomerID = S.CustomerID)
AND S.OrderID = (SELECT MIN(OrderID) FROM dbo.StageOrders AS S2
WHERE S2.CustomerID = S.CustomerID);
--方案四: Insert New Customers From StageOrders using Row Numbers
INSERT INTO dbo.MyCustomers(CustomerID, CompanyName, ContactName,
ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax)
SELECT CustomerID, CompanyName, ContactName,
ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax
FROM (SELECT
ROW_NUMBER() OVER(PARTITION BY CustomerID ORDER BY OrderID) AS rn,
CustomerID, CompanyName, ContactName, ContactTitle, Address, City,
Region, PostalCode, Country, Phone, Fax
FROM dbo.StageOrders) AS S
WHERE NOT EXISTS
(SELECT * FROM dbo.MyCustomers AS T
WHERE T.CustomerID = S.CustomerID)
AND rn = 1;
GO
4、带有output的insert
通过使用新的output子句,Sql Server 2005支持从数据修改语句中返回输出
例子:
IF OBJECT_ID('dbo.CustomersDim') IS NOT NULL
DROP TABLE dbo.CustomersDim;
GO
CREATE TABLE dbo.CustomersDim
(
KeyCol INT NOT NULL IDENTITY PRIMARY KEY,
CustomerID NCHAR(5) NOT NULL,
CompanyName NVARCHAR(40) NOT NULL,
/* ... other columns ... */
);
-- Insert New Customers and Get their Surrogate Keys
DECLARE @NewCusts TABLE
(
CustomerID NCHAR(5) NOT NULL PRIMARY KEY,
KeyCol INT NOT NULL UNIQUE
);
INSERT INTO dbo.CustomersDim(CustomerID, CompanyName)
OUTPUT inserted.CustomerID, inserted.KeyCol
INTO @NewCusts
--OUTPUT inserted.CustomerID, inserted.KeyCol
SELECT CustomerID, CompanyName
FROM Northwind.dbo.Customers
WHERE Country = N'UK';
SELECT CustomerID, KeyCol FROM @NewCusts;
GO
二、删除数据
1、truncate 和 delete
如果你要从表中移除所有行,应该使用truncate table,而不应该使用不带where子句的delete。delete总是被完整的记录到日志,而truncate table总是按最小方式被记录到日志
truncate table 和 delete 除了在性能方面有巨大差异外,它们对identity属性的处理方式也不同.truncate table 把identity属性重置为最初的种子,而delete则不会
2、移除包含重复数据的行
解决方案一:要求整行都重复
SELECT DISTINCT * INTO dbo.OrdersTmp FROM dbo.OrdersDups;
DROP TABLE dbo.OrdersDups;
EXEC sp_rename 'dbo.OrdersTmp', 'OrdersDups';
解决方案二:要求表中有唯一标识符
DELETE FROM dbo.OrdersDups
WHERE EXISTS
(SELECT *
FROM dbo.OrdersDups AS O2
WHERE O2.OrderID = dbo.OrdersDups.OrderID
AND O2.KeyCol > dbo.OrdersDups.KeyCol);
GO
解决方案三:要求表中有唯一标识符
SELECT O.OrderID, CustomerID, EmployeeID, OrderDate, RequiredDate,
ShippedDate, ShipVia, Freight, ShipName, ShipAddress, ShipCity,
ShipRegion, ShipPostalCode, ShipCountry
INTO dbo.OrdersTmp
FROM dbo.OrdersDups AS O
JOIN (SELECT OrderID, MAX(KeyCol) AS mx
FROM dbo.OrdersDups
GROUP BY OrderID) AS U
ON O.OrderID = U.OrderID
AND O.KeyCol = U.mx;
DROP TABLE dbo.OrdersDups;
EXEC sp_rename 'dbo.OrdersTmp', 'OrdersDups';
解决方案四:用cte和row_number函数实现一种快速的解决方案
WITH Dups AS
(
SELECT *,
ROW_NUMBER() OVER(PARTITION BY OrderID ORDER BY OrderID) AS rn
FROM dbo.OrdersDups
)
DELETE FROM Dups WHERE rn > 1;
GO
3、基于联接的delete
--非标准查询
BEGIN TRAN
DELETE FROM OD
FROM dbo.[Order Details] AS OD
JOIN dbo.Orders AS O
ON OD.OrderID = O.OrderID
WHERE O.OrderDate >= '19980506';
ROLLBACK TRAN
--标准查询
BEGIN TRAN
DELETE FROM dbo.[Order Details]
WHERE EXISTS
(SELECT *
FROM dbo.Orders AS O
WHERE O.OrderID = dbo.[Order Details].OrderID
AND O.OrderDate >= '19980506');
ROLLBACK TRAN
GO
4、带有output的delete
例子:
WHILE 1=1
BEGIN
BEGIN TRAN
DELETE TOP(5000) FROM dbo.LargeOrders
OUTPUT deleted.* INTO dbo.OrdersArchive
WHERE OrderDate < '20010101';
IF @@rowcount < 5000
BEGIN
COMMIT TRAN
BREAK;
END
COMMIT TRAN
END
GO
三、更新数据
1、基于联接的update
例子:
方案一:
UPDATE O
SET ShipCountry = C.Country,
ShipRegion = C.Region,
ShipCity = C.City
FROM dbo.Orders AS O
JOIN dbo.Customers AS C
ON O.CustomerID = C.CustomerID
WHERE C.Country = 'USA';
方案二:
WITH UPD_CTE AS
(
SELECT
O.ShipCountry AS set_Country, C.Country AS get_Country,
O.ShipRegion AS set_Region, C.Region AS get_Region,
O.ShipCity AS set_City, C.City AS get_City
FROM dbo.Orders AS O
JOIN dbo.Customers AS C
ON O.CustomerID = C.CustomerID
WHERE C.Country = 'USA'
)
UPDATE UPD_CTE
SET set_Country = get_Country,
set_Region = get_Country,
set_City = get_City;
2、select和update赋值语句
赋值select
如果表中没有记录则为null,如果有多条记录则为最后一跳记录的值
DECLARE @EmpID AS INT, @Pattern AS NVARCHAR(100);
SET @Pattern = N'Davolio'; -- Try also N'Ben-Gan', N'D%';
SET @EmpID = 999;
SET @EmpID = (SELECT EmployeeID
FROM dbo.Employees
WHERE LastName LIKE @Pattern);
SELECT @EmpID;
GO
赋值update
CREATE TABLE dbo.T1
(
col1 INT NOT NULL,
col2 VARCHAR(5) NOT NULL
);
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'A');
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'B');
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'C');
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'C');
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'C');
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'B');
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'A');
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'A');
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'C');
INSERT INTO dbo.T1(col1, col2) VALUES(0, 'C');
go
方案一:
DECLARE @i AS INT;
SET @i = 0;
UPDATE dbo.T1 SET @i = col1 = @i + 1;
逻辑上,这个set语句等价于set col1=@i+1,@i=@i+1
在update语句中,你无法控制T1中的行被扫描和修改的顺序
GO
方案二:
-- SQL Server 2005
WITH T1RN AS
(
SELECT col1, ROW_NUMBER() OVER(ORDER BY col2) AS RowNum
FROM dbo.T1
)
UPDATE T1RN SET col1 = RowNum;
GO
发表评论
-
SQL Server 2005中处理表分区问题
2008-08-28 11:01 2011数据库性能调优是每一 ... -
SQL LIKE 通配符随笔
2008-07-04 09:26 1603通配符 说明 _ 与任意单字符匹配 % 与包含一 ... -
五种提高 SQL 性能的方法
2008-07-02 12:10 1127有时, 为了让应用程序运行得更快,所做的全部工作就是在这里或那 ... -
SQL操作全集
2008-07-02 12:01 1113SQL分类: DDL—数据定义语言(CREATE,ALTER, ... -
不同服务器数据库之间的数据操作
2008-07-02 11:56 1915--创建链接服务器 exec sp_addlinkedser ... -
远程连接操作
2008-07-02 11:52 1287--远程连接操作 /******************** ... -
合并分拆表
2008-07-02 11:46 1452--合并分拆表 /********************** ... -
行列互转
2008-07-02 11:45 1388--行列互转 /*********************** ... -
T-SQL查询学习笔记——求下属和祖先的算法
2008-04-10 14:08 1900构建试验环境: CREATE TABLE dbo.Employ ... -
T-SQL查询学习笔记——使用TOP和APPLY解决常见问题
2008-04-09 14:45 20721、每组中的TOP n问题 CREATE UNIQUE IND ... -
T-SQL查询学习笔记——TOP子句
2008-04-09 13:59 3204在select查询或表表达式中,top结合order by子句 ... -
T-SQL查询学习笔记——分组因子的使用示例
2008-04-08 17:27 1652IF OBJECT_ID('Stocks') IS NOT N ... -
T-SQL查询学习笔记——求中值的几种方法
2008-04-08 11:28 2769中值有两种定义: 1、当组中包含奇数个元素时,我们将直接返回中 ... -
Over 字句
2008-04-07 17:34 1530功能:确定在应用关联的窗口函数之前,行集的分区和排序。 适用 ... -
sql 的随机函数newID()和RAND()
2008-03-20 11:05 3057SELECT * FROM Northwind..Orders ... -
T-SQL查询学习笔记——已有范围和缺失范围示例代码
2008-03-19 15:30 1891USE SqlTest;GOIF OBJECT_ID('db ... -
T-SQL查询学习笔记——快速生成数字辅助表的几种方法示例代码
2008-03-19 14:17 2302------------------------------- ... -
SELECT 与 SET 对变量赋值的区别
2008-03-17 15:29 2824SQL Server 中对已经定义的变量赋值的方式用两种,分别 ... -
SQL逻辑查询处理步骤
2008-03-14 17:22 17591、执行笛卡尔乘积(交叉联接) 2、应用ON筛选器(联接条件) ... -
Server 2005 中集合操作(UNION、EXCEPT、INTERSECT)
2008-03-14 16:32 1439集合操作在两个输入中比较全部行。 Union:返回 ...
相关推荐
主要内容包括SQL的基础理论、查询优化、查询算法及复杂度,以及在使用子查询、表表达式、排名函数、数据聚合和透视转换、TOP和APPLY、数据修改、分区表、特殊数据结构等实际应用时会遇到的各种高级查询问题和解决...
《Microsoft SQL Server 2008技术内幕:T-SQL查询》是一本深入探讨SQL Server 2008中T-SQL(Transact-SQL)查询的权威指南。T-SQL是微软SQL Server数据库管理系统的核心语言,用于数据操作、查询、存储过程编写以及...
T-SQL(Transact-SQL)是Microsoft SQL Server数据库管理系统中用于数据操作、查询、存储过程和数据库控制的一种扩展SQL语法。此书主要关注于如何高效地使用T-SQL进行数据检索和处理,为数据库管理员和开发人员提供...
本书及其续篇——《Microsoft SQL Server 2005技术内幕:T-SQL程序设计》介绍了SQL Server 2005中高级T-SQL查询、查询优化及编程相关的知识。这两本书侧重于解决实践中的常见问题,并讨论了解决这些问题的方法。它们...
《SQL2008技术内幕——T-SQL查询》是一本深入探讨Microsoft SQL Server 2008数据库管理系统中T-SQL(Transact-SQL)查询的权威指南。T-SQL是SQL Server的核心语言,用于数据操作、存储过程编写、触发器定义以及...
SQL Server 2005 技术内幕:T-SQL 查询笔记 本笔记涵盖了 SQL Server 2005 技术内幕中 T-SQL 查询的前两章内容,主要介绍了逻辑查询处理、查询优化器、查询执行步骤、查询筛选器、聚合函数、子查询、别名的使用限制...
5. **Chapter 08 - Data Modification**:这一部分聚焦于如何使用T-SQL修改数据,包括INSERT语句来插入新记录,UPDATE用于更新现有记录,以及DELETE语句用于删除数据。同时会涉及数据完整性与事务处理。 6. **...
T-SQL是微软数据库管理系统SQL Server的主要编程语言,用于执行数据查询、更新、插入和删除等操作。了解并熟练掌握T-SQL查询对于任何SQL Server数据库管理员或开发人员来说都是至关重要的。 本书可能涵盖了以下几个...
### 关于《Inside Microsoft SQL Server 2008 T-SQL Programming》的知识点解析 #### 一、SQL Server 2008概述 《Inside Microsoft SQL Server 2008 T-SQL Programming》这本书深入地介绍了SQL Server 2008的各项...
标题中提到的“Microsoft SQL Server 2008技术内幕:T-SQL查询”指向了两方面的知识内容:一是Microsoft SQL Server数据库管理系统,二是T-SQL(Transact-SQL)语言,这是SQL Server中用于数据操作和管理的专有扩展...
T-SQL,全称Transact-SQL,是SQL语言的一个扩展,主要用于Microsoft SQL Server数据库管理系统。它是数据库查询、数据更新、事务...通过学习和实践这些示例,你可以深入了解T-SQL的强大功能,并提升数据库管理技能。
通过深入学习《Microsoft SQL Server 2008技术内幕:T-SQL查询》这本书,读者将能够熟练地使用T-SQL进行数据查询、操作和分析,从而更好地应对实际工作中的挑战。书中的源代码和附录A提供了丰富的实践示例,进一步...
T-SQL(Transact-SQL)是SQL Server的标准查询语言,它是SQL的扩展,包含了SQL的所有功能,并增加了一些特有的编程元素,如过程、函数和事务控制等。 在SQL Server 2008中,T-SQL是进行数据管理、分析和应用程序...
T-SQL,即Transact-SQL,是SQL的一个扩展,主要用于微软的SQL Server系统中,用于数据查询、更新、插入和删除,以及复杂的存储过程和触发器的编写。 在SQL Server 2008版本中,T-SQL得到了许多增强和改进,这本书将...
元数据函数可以将对象ID转换为名称,或由对象名称反查对象ID,大大简化了SQL查询的复杂性。比如,可以不必通过sys.tables视图,直接通过sys.key_constraints视图列出每个表的主键信息。 Transact-SQL元编程的实际...
《T-SQL学习资料》是针对SQL SERVER 2005数据库系统中T-SQL语言的一份综合学习资源,这份集合包含文档、手册和视频教程,旨在帮助从Oracle转向SQL SERVER的开发者快速掌握T-SQL的基本概念和高级技巧。 T-SQL...
理解并熟练掌握T-SQL是任何SQL Server开发者的必备技能,这包括但不限于数据查询、数据修改、存储过程编写、事务管理、错误处理等多个方面。深入学习T-SQL能够提升你在数据库管理和开发领域的专业能力,使你能够更加...
T-SQL(Transact-SQL)是SQL Server专用的数据库查询语言,它是标准SQL语言的扩展,通过增加流程控制语句、变量、函数等,来支持复杂的数据处理任务。 在本节中,我们重点介绍T-SQL的基础知识,内容将涵盖以下几个...
其基本语法包括数据查询语言(DQL)、数据操纵语言(DML)、数据定义语言(DDL)和数据控制语言(DCL)。DQL用于检索数据,如`SELECT`语句;DML用于插入、更新和删除数据,如`INSERT`、`UPDATE`和`DELETE`;DDL用于...
T-SQL是SQL Server的核心组件,用于数据查询、操作、分析以及数据库对象的创建和管理。本教程旨在帮助初学者和有一定经验的数据库管理员深入理解并熟练掌握T-SQL。 在SQL Server 2012中,T-SQL提供了一系列的关键...