日期:2014-05-18  浏览次数:20538 次

求30条经典的SQL语句,或是T-SQL语句.随后再开贴放分.
功能不限:

只要你认为经典的、
或是功能强大的、
或是最为基本的、
或是连接查询(包括自连接)、
或是分布式查询、
或是异构查询、


同时还望大家在贴出来的时候标明注释。以供大家学习与交流!


当然不要全部都贴   select   *   from   T_name

------解决方案--------------------
那就贴一个吧:
DECLARE @idoc int
DECLARE @doc varchar(1000)
SET @doc = '
<ROOT>
<Customer CustomerID= "VINET " ContactName= "Paul Henriot ">
<Order CustomerID= "VINET " EmployeeID= "5 " OrderDate= "1996-07-04T00:00:00 ">
<OrderDetail OrderID= "10248 " ProductID= "11 " Quantity= "12 "/>
<OrderDetail OrderID= "10248 " ProductID= "42 " Quantity= "10 "/>
</Order>
</Customer>
<Customer CustomerID= "LILAS " ContactName= "Carlos Gonzlez ">
<Order CustomerID= "LILAS " EmployeeID= "3 " OrderDate= "1996-08-16T00:00:00 ">
<OrderDetail OrderID= "10283 " ProductID= "72 " Quantity= "3 "/>
</Order>
</Customer>
</ROOT> '
--Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
-- Execute a SELECT statement that uses the OPENXML rowset provider.
SELECT *
FROM OPENXML (@idoc, '/ROOT/Customer ',1)
WITH (CustomerID varchar(10),
ContactName varchar(20))
EXEC sp_xml_removedocument @idoc
------解决方案--------------------
关于索引,推荐转载的这篇文章
http://blog.csdn.net/dutguoyi/archive/2006/01/10/575617.aspx

改善SQL语句的效率
http://community.csdn.net/Expert/topic/5087/5087396.xml?temp=.345669
数据量很大怎样加快索检速度
http://community.csdn.net/Expert/topic/5058/5058320.xml?temp=.1229517
索引建立方法的区别
http://community.csdn.net/Expert/topic/5068/5068154.xml?temp=.3010218
频繁插入删除数据需要更新索引
http://community.csdn.net/Expert/topic/4937/4937910.xml?temp=.8428614
测试了一下sql server 2005 全文检索
http://community.csdn.net/Expert/topic/4878/4878430.xml?temp=.6049311

其他关于效率的高频问题

判断一个表的数据不在另一个表中最优秀方法?
http://community.csdn.net/Expert/topic/5038/5038742.xml?temp=.4704553
删除千万级表中重复记录的办法
http://community.csdn.net/Expert/topic/5089/5089261.xml?temp=.7907068

数据库数据查询变得不正常类型问题

大数据量,稳定运行一段时候以后无法得到查询结果。
http://community.csdn.net/Expert/topic/4810/4810464.xml?temp=9.014529E-02
------解决方案--------------------
返回表的字段名称

select name from syscolumns where id=object_id( 'jobs ')
------解决方案--------------------
select * into b
from a where 1 <> 1

--刚看到的.新建一个与a表一样的空的b表
------解决方案--------------------
准备收藏此贴~
------解决方案--------------------
一些不错的sql语句,自己根据需要收藏吧,分给多点哦:)
1、说明:复制表(只复制结构,源表名:a 新表名:b) (Access可用)
法一:select * into b from a where 1 <> 1
法二:select top 0 * into b from a

2、说明:拷贝表(拷贝数据,源表名:a 目标表名:b) (Access可用)
insert into b(a, b, c) select d,e,f from b;

3、说明:跨数据库之间表的拷贝(具体数据使用绝对路径) (Access可用)
insert into b(a, b, c) select d,e,f from b in ‘具体数据库’ where 条件
例子:..from b in ' "&Server.MapPath( ". ")& "\data.mdb " & " ' where..

4、说明:子查询(表名1:a 表名2:b)