T-SQL学习笔记

CONVERT的使用
declare @binvalue varbinary(256),
@vcharvalue nvarchar(256)
set @binvalue=convert (varbinary (20) , 'select')
select convert (varbinary (20) , 'select')
select convert (varchar (20), 0x73656c656374 )
 
COMMIT / ROLLBACK
COMMIT / ROLLBACK 都是用在执行 DML语句(INSERT / DELETE / UPDATE / SELECT )之后的。DML 语句,执行完之后,处理的数据,都会放在回滚段中(除了 SELECT 语句),等待用户进行提交(COMMIT)或者回滚 (ROLLBACK),当用户执行 COMMIT / ROLLBACK后,放在回滚段中的数据就会被删除。
所有的 DML 语句都是要显式提交的,也就是说要在执行完DML语句之后,执行 COMMIT
而其他的诸如 DDL 语句的,都是隐式提交的
begin   tran   aa   
commit   tran   aa  
从外部数据源插入BLOB
INSERT INTO BLOBTest
(BLOBName, BLOBData)
SELECT 'First test file',
 BulkColumn FROM OPENROWSET(
 Bulk 'D:  est.jpg', SINGLE_BLOB) AS BLOB
这里用“D:  est.jpg”代入作为文件的文件系统路径。OPENROWSET语句允许SQL从外部数据源提供程序来存取数据。Bulk是特别为OPENROWSET插入文件和图像而设计的数据源提供程序
 
在sql2005 中,Ad Hoc Distributed Queries用服务默认是关闭的
解決辦法:
使用前启用: (Ad Hoc Distributed Queries)
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
使用後关闭: (Ad Hoc Distributed Queries)
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
 
通过Ad Hoc Distributed Queries查询外部数据
SELECT Number
   FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
      'E:\LeandRo\WorkSpace\InventionTool 2007\Invention Tool 3.0\Data\Conflict\UserConflict.mdb';
      'admin';'',UserExample)
 
AdventureWorks.Sales.Currency 表中的 out 选项。此示例创建一个名为 Currency.dat 的数据文件,并使用字符格式将表数据复制到该文件中
bcp AdventureWorks.Sales.Currency out Currency.dat -T -c
 
列出所有存储过程
SELECT * FROM SysObjects WHERE [xtype] = 'P'
 
查询存储过程的内容
EXEC Sp_HelpText '存储过程名'
 
查询空字符串
SELECT SPACE(空字符个数)
 
C#中调用存储过程
SqlCommand getrc = new SqlCommand();
getrc.CommandType = CommandType.StoredProcedure;
getrc.CommandText = "YourSPName";
getrc.Connection = YourSqlConnection; 
getrc.Parameters.AddWithValue("@a","A");
getrc.Parameters.Add(new SqlParameter("@b", "abc")); 
getrc.ExecuteNonQuery(); 
posted @ 2008-05-15 22:02  湘西小刁民  阅读(233)  评论(0编辑  收藏  举报