SQL Native Client ODBC Driver
标准安全连接
Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
您是否在使用SQL Server 2005 Express 请在“Server”选项使用连接表达式“主机名称\SQLEXPRESS”。
受信的连接
Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;
"Integrated Security=SSPI" 与 "Trusted_Connection=yes" 是相同的。
连接到一个SQL Server实例
指定服务器实例的表达式和其他SQL Server的连接字符串相同。
Driver={SQL Native Client};Server=myServerName\theInstanceName;Database=myDataBase;Trusted_Connection=yes;
指定用户名和密码
oConn.Properties("Prompt") = adPromptAlways
Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;
使用MARS (multiple active result sets)
Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;MARS_Connection=yes;
"MultipleActiveResultSets=true"与MARS_Connection=yes"是相同的。
......
MS Sql server 数据库
1.按定义时存储状态分行显示定义(sp_helptext存储过程),调用:Exec sp_helptext '对象名'
2.以表格形式显示返回相关参数(sys.objects视图),调用:select * from sys.objects where name='对象名'
3.作为结果集显示定义(object_definition),调用:select object_definition(object_id('对象名')) as 'aaa'
可用于下列对象:
C = Check constraint
D = Default (constraint or stand-alone)
P = SQL stored procedure
FN = SQL scalar function
R = Rule
RF = Replication filter procedure
TR = SQL trigger (schema-scoped DML trigger, or DDL trigger at either the database or server scope)
IF = SQL inline table-valued function
TF = SQL table-valued function
V = View ......
IN
确定给定的值是否与子查询或列表中的值相匹配。
EXISTS
指定一个子查询,检测行的存在。
比较使用 EXISTS 和 IN 的查询
这个例子比较了两个语义类似的查询。第一个查询使用 EXISTS 而第二个查询使用 IN。注意两个查询返回相同的信息。
USE pubs
GO
SELECT DISTINCT pub_name
from publishers
WHERE EXISTS
(SELECT *
from titles
WHERE pub_id = publishers.pub_id
AND type = 'business')
GO
-- Or, using the IN clause:
USE pubs
GO
SELECT distinct pub_name
from publishers
WHERE pub_id IN
(SELECT pub_id
from titles
WHERE type = 'business')
GO
下面是任一查询的结果集:
pub_name
----------------------------------------
Algodata Infosystems
New Moon Books
(2 row(s) affected) ......
一、基础
1、说明:创建数据库
Create DATABASE database-name
2、说明:删除数据库
drop database dbname
3、说明:备份sql server
--- 创建 备份数据的 device
USE master
EXEC sp_addumpdevice disk, testBack, c:mssql7backupMyNwind_1.dat
--- 开始 备份
BACKUP DATABASE pubs TO testBack
4、说明:创建新表
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
根据已有的表创建新表:
A:create table tab_new like tab_old (使用旧表创建新表)
B:create table tab_new as select col1,col2… from tab_old definition only
5、说明:删除新表
drop table tabname
6、说明:增加一个列
Alter table tabname add column col type
注:列增加后将不能删除。DB2中列加上后数据类型也不能改变,唯一能改变的是增加varchar类型的长度。
7、说明:添加主键: Alter table tabname add primary key(col)
说明:删除主键: Alter table tabname drop primary key(col)
8、说明:创建索引:create [unique] index idxname on tabname(col….)
删除索引:drop index idxname
......
依据csdn高手写的自己练习一下方便以后查找
--Creator:Gongl
--Date:2009-1-8
--sql server 2000
--学习行转列,为了进一步了解动态sql拼接(单双三引号)
--几种类型
--Numeric(10,2) 指字段是数字型,长度为10 小数为两位
--varchar和nvarchar的区别
--1.从存储方式上,nvarchar是按字符存储的,而 varchar是按字节存储的;
--2.从存储量上考虑, varchar比较节省空间,因为存储大小为字节的实际长度,而 nvarchar是双字节存储;
--3.在使用上,如果存储内容都是英文字符而没有汉字等其他语言符号,建议使用varchar;含有汉字的使用nvarchar,因为nvarchar是使用Unicode编码,即统一的字符编码标准,会减少乱码的出现几率;
----行转列
--创建测试数据
if object_id('idl') is not null drop table idl
create table idl(name varchar(10),subject nvarchar(10),score numeric(4,1))
insert into idl
select 'anny','数学',95.5 union all
select 'anny','语文',90 union all
select 'anny','英语',99 union all
select 'anny','asp.net',100 union all
select 'anny','sqlserver',100 union all
select 'jenny','数学',94.5 union all
select 'jenny' ......
MSSQL:
declare @begin datetime
declare @End datetime
set @begin=getdate()
--执行的语句写在这里
set @End=getdate()
select datediff(millisecond,@begin,@End) as 执行的时间
--millisecond表示毫秒 如果看秒可以使用ss
C#:
很多时候,我们对自己的程序的瓶颈不是很清楚。如一个本地类和一个webservice之间的调用到底是有多大的区别。页面整个的执行时间怎么样监控。程序是在那个地方化的时间最长。现在我就把.NET2.0以后的监控方法说下。其实很简单,只要在System.Diagnostics 中就有一个可以直接使用的类 --Stopwatch。不多说了。将代码贴出来。
protected void Page_Load(object sender, EventArgs e)
{
Stopwatch watch = new Stopwatch(); //实例化一个监控对象
watch.Start(); //开始监控业务逻辑
&nb ......
MSSQL:
declare @begin datetime
declare @End datetime
set @begin=getdate()
--执行的语句写在这里
set @End=getdate()
select datediff(millisecond,@begin,@End) as 执行的时间
--millisecond表示毫秒 如果看秒可以使用ss
C#:
很多时候,我们对自己的程序的瓶颈不是很清楚。如一个本地类和一个webservice之间的调用到底是有多大的区别。页面整个的执行时间怎么样监控。程序是在那个地方化的时间最长。现在我就把.NET2.0以后的监控方法说下。其实很简单,只要在System.Diagnostics 中就有一个可以直接使用的类 --Stopwatch。不多说了。将代码贴出来。
protected void Page_Load(object sender, EventArgs e)
{
Stopwatch watch = new Stopwatch(); //实例化一个监控对象
watch.Start(); //开始监控业务逻辑
&nb ......