Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB
ÈÈÃűêÇ©£º c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 ×îÐÂÎÄÕ : mssql

ASP²ÉÓÃODBCÊý¾ÝÔ´Á¬½ÓMSSQLÊý¾Ý¿âÏêϸ˵Ã÷¡¾ÊµÓá¿

ODBCÊý¾ÝÔ´¿É·ÖΪ“ϵͳÐÍ”ºÍ“ÎļþÐÍ”£¬ËûÃǵÄÇø±ðÔÚÓړϵͳÐÍ”ÊÇÁ¬½ÓÊý¾Ý¿âµÄÐÅÏ¢½¨Á¢Ôړϵͳע²á±í”À“ÎļþÐÍ”ÔòÊÇÒÔdsnÎļþÐÎʽ´æ´¢ÔÚODBCÔ´µÄĿ¼ÏÂÃæ
Ò»¡¢½¨Á¢ODBCÊý¾ÝÔ´µÄ·½·¨£º
¿ØÖÆÃæ°å - ¹ÜÀí¹¤¾ß - Êý¾ÝÔ´£¨ODBC£©
´ò¿ªODBCÊý¾ÝÔ´¹ÜÀíÆ÷£¬È»ºóÒ»²½²½°´ÕÕÐèÒª½¨Á¢“ϵͳDSN”»òÕß“ÎļþDSN”
(½¨Òé°Ñн¨Á¢µÄÎļþDSN±£´æÔÚODBCÔ´µÄĿ¼ÏÂÃ棬±ãÓÚÁ¬½Ó)
¶þ¡¢MSSQLµÄÊý¾Ý¿âÁ¬½Ó×Ö·û´®Ð´·¨£º
1¡¢Í¨¹ýoledb½¨Á¢Á¬½Ó
conn.open ""Provider=SQLOLEDB;server=(SQL·þÎñÆ÷Ãû³Æ»òIPµØÖ·);database=Êý¾Ý¿âÃû³Æ;uid=;pwd=""
2¡¢Í¨¹ýdriver½¨Á¢Á¬½Ó
conn.open ""driver={sql server};server=(SQL·þÎñÆ÷Ãû³Æ»òIPµØÖ·);database=Êý¾Ý¿âÃû³Æ;uid=;pwd=""
3¡¢Í¨¹ýODBC DSN½¨Á¢Á¬½Ó
ϵͳDSNÁ¬½Ó
conn.open ""DSN=(ϵͳDSNÃû³Æ);Database=Êý¾Ý¿âÃû³Æ;UID=;PWD=;""
ÎļþDSNÁ¬½Ó1
conn.open ""FileDSN=(ÎļþDSNÃû³Æ.dsn);Database=Êý¾Ý¿âÃû³Æ;UID=;PWD=;""
Àý£ºconn.open ""FileDSN=test.dsn;Database=mytest;UID=test;PWD=1234;""
ÎļþDSNÁ¬½Ó2(°²È«ÐÔ×î¸ß)
---ºÍµÚÒ»ÖÖ·½·¨ÀàËÆ,Ö»Ê ......

ASP²ÉÓÃODBCÊý¾ÝÔ´Á¬½ÓMSSQLÊý¾Ý¿âÏêϸ˵Ã÷¡¾ÊµÓá¿

ODBCÊý¾ÝÔ´¿É·ÖΪ“ϵͳÐÍ”ºÍ“ÎļþÐÍ”£¬ËûÃǵÄÇø±ðÔÚÓړϵͳÐÍ”ÊÇÁ¬½ÓÊý¾Ý¿âµÄÐÅÏ¢½¨Á¢Ôړϵͳע²á±í”À“ÎļþÐÍ”ÔòÊÇÒÔdsnÎļþÐÎʽ´æ´¢ÔÚODBCÔ´µÄĿ¼ÏÂÃæ
Ò»¡¢½¨Á¢ODBCÊý¾ÝÔ´µÄ·½·¨£º
¿ØÖÆÃæ°å - ¹ÜÀí¹¤¾ß - Êý¾ÝÔ´£¨ODBC£©
´ò¿ªODBCÊý¾ÝÔ´¹ÜÀíÆ÷£¬È»ºóÒ»²½²½°´ÕÕÐèÒª½¨Á¢“ϵͳDSN”»òÕß“ÎļþDSN”
(½¨Òé°Ñн¨Á¢µÄÎļþDSN±£´æÔÚODBCÔ´µÄĿ¼ÏÂÃ棬±ãÓÚÁ¬½Ó)
¶þ¡¢MSSQLµÄÊý¾Ý¿âÁ¬½Ó×Ö·û´®Ð´·¨£º
1¡¢Í¨¹ýoledb½¨Á¢Á¬½Ó
conn.open ""Provider=SQLOLEDB;server=(SQL·þÎñÆ÷Ãû³Æ»òIPµØÖ·);database=Êý¾Ý¿âÃû³Æ;uid=;pwd=""
2¡¢Í¨¹ýdriver½¨Á¢Á¬½Ó
conn.open ""driver={sql server};server=(SQL·þÎñÆ÷Ãû³Æ»òIPµØÖ·);database=Êý¾Ý¿âÃû³Æ;uid=;pwd=""
3¡¢Í¨¹ýODBC DSN½¨Á¢Á¬½Ó
ϵͳDSNÁ¬½Ó
conn.open ""DSN=(ϵͳDSNÃû³Æ);Database=Êý¾Ý¿âÃû³Æ;UID=;PWD=;""
ÎļþDSNÁ¬½Ó1
conn.open ""FileDSN=(ÎļþDSNÃû³Æ.dsn);Database=Êý¾Ý¿âÃû³Æ;UID=;PWD=;""
Àý£ºconn.open ""FileDSN=test.dsn;Database=mytest;UID=test;PWD=1234;""
ÎļþDSNÁ¬½Ó2(°²È«ÐÔ×î¸ß)
---ºÍµÚÒ»ÖÖ·½·¨ÀàËÆ,Ö»Ê ......

MsSql ²é¿´ÐÅÏ¢ºÃÓï¾ä

set statistics profile on
set statistics io on
set statistics time on
select top 1 * from et_order order by pkid desc
½á¹ûÈçÏ£º
SQL Server ·ÖÎöºÍ±àÒëʱ¼ä:
   CPU ʱ¼ä = 0 ºÁÃ룬ռÓÃʱ¼ä = 1 ºÁÃë¡£
SQL Server Ö´ÐÐʱ¼ä:
   CPU ʱ¼ä = 0 ºÁÃ룬ռÓÃʱ¼ä = 1 ºÁÃë¡£
SQL Server Ö´ÐÐʱ¼ä:
   CPU ʱ¼ä = 0 ºÁÃ룬ռÓÃʱ¼ä = 1 ºÁÃë¡£
SQL Server Ö´ÐÐʱ¼ä:
   CPU ʱ¼ä = 0 ºÁÃ룬ռÓÃʱ¼ä = 1 ºÁÃë¡£
(1 ÐÐÊÜÓ°Ïì)
±í 'ET_Order'¡£É¨Ãè¼ÆÊý 1£¬Âß¼­¶ÁÈ¡ 4 ´Î£¬ÎïÀí¶ÁÈ¡ 0 ´Î£¬Ô¤¶Á 0 ´Î£¬lob Âß¼­¶ÁÈ¡ 0 ´Î£¬lob ÎïÀí¶ÁÈ¡ 0 ´Î£¬lob Ô¤¶Á 0 ´Î¡£
(3 ÐÐÊÜÓ°Ïì)
SQL Server Ö´ÐÐʱ¼ä:
   CPU ʱ¼ä = 0 ºÁÃ룬ռÓÃʱ¼ä = 8 ºÁÃë¡£
ÁíÒ»¸ö°ì·¨Îª£º
declare   @begin_date   datetime  
  declare   @end_date   datetime  
  select   @begin_date   =   getdate()  
  exec   ´æ´¢¹ý³Ì    
  select   @end_date   =   getdate()  
  select   datedi ......

ʵÏÖ¶àÐкϲ¢Ò»ÐеÄSQL [MSSQL2005]д·¨

--1. ´´½¨±í£¬Ìí¼Ó²âÊÔÊý¾Ý
CREATE TABLE tb(id int, [value] varchar(10))
INSERT tb SELECT 1, 'aa'
UNION ALL SELECT 1, 'bb'
UNION ALL SELECT 2, 'aaa'
UNION ALL SELECT 2, 'bbb'
UNION ALL SELECT 2, 'ccc'
--SELECT * from tb
/**//*
id value
----------- ----------
1 aa
1 bb
2 aaa
2 bbb
2 ccc
(5 row(s) affected)
*/
--2 ÔÚSQL2000Ö»ÄÜÓÃ×Ô¶¨Ò庯ÊýʵÏÖ
----2.1 ´´½¨ºÏ²¢º¯Êýfn_strSum£¬¸ù¾ÝidºÏ²¢valueÖµ
GO
CREATE FUNCTION dbo.fn_strSum(@id int)
RETURNS varchar(8000)
AS
BEGIN
DECLARE @values varchar(8000)
SET @values = ''
SELECT @values = @values + ',' + value from tb WHERE id=@id
RETURN STUFF(@values, 1, 1, '')
END
GO
-- µ÷Óú¯Êý
SELECT id, VALUE = dbo.fn_strSum(id) from tb GROUP BY id
DROP FUNCTION dbo.fn_strSum
----2.2 ´´½¨ºÏ²¢º¯Êýfn_strSum2£¬¸ù¾ÝidºÏ²¢valueÖµ
GO
CREATE FUNCTION dbo.fn_strSum2(@id int)
RETURNS varchar(8000)
AS
BEGIN
DECLARE @values varchar(8000)
SELECT @values = isnull(@values + ',', '') + value from t ......

ʵÏÖ¶àÐкϲ¢Ò»ÐеÄSQL [MSSQL2005]д·¨

--1. ´´½¨±í£¬Ìí¼Ó²âÊÔÊý¾Ý
CREATE TABLE tb(id int, [value] varchar(10))
INSERT tb SELECT 1, 'aa'
UNION ALL SELECT 1, 'bb'
UNION ALL SELECT 2, 'aaa'
UNION ALL SELECT 2, 'bbb'
UNION ALL SELECT 2, 'ccc'
--SELECT * from tb
/**//*
id value
----------- ----------
1 aa
1 bb
2 aaa
2 bbb
2 ccc
(5 row(s) affected)
*/
--2 ÔÚSQL2000Ö»ÄÜÓÃ×Ô¶¨Ò庯ÊýʵÏÖ
----2.1 ´´½¨ºÏ²¢º¯Êýfn_strSum£¬¸ù¾ÝidºÏ²¢valueÖµ
GO
CREATE FUNCTION dbo.fn_strSum(@id int)
RETURNS varchar(8000)
AS
BEGIN
DECLARE @values varchar(8000)
SET @values = ''
SELECT @values = @values + ',' + value from tb WHERE id=@id
RETURN STUFF(@values, 1, 1, '')
END
GO
-- µ÷Óú¯Êý
SELECT id, VALUE = dbo.fn_strSum(id) from tb GROUP BY id
DROP FUNCTION dbo.fn_strSum
----2.2 ´´½¨ºÏ²¢º¯Êýfn_strSum2£¬¸ù¾ÝidºÏ²¢valueÖµ
GO
CREATE FUNCTION dbo.fn_strSum2(@id int)
RETURNS varchar(8000)
AS
BEGIN
DECLARE @values varchar(8000)
SELECT @values = isnull(@values + ',', '') + value from t ......

ubuntuÖÐÁ¬½ÓmssqlÊý¾Ý¿â

»ù±¾Ô­Àí
FreeTDSΪLinuxϵͳÌṩÁËTDSЭÒéµÄ¿ªÔ´¿Í»§¶Ë¡£ÓÉÓÚMS SQLºÍSybaseʹÓõÄÇ¡ÊÇTDSЭÒ飬ËùÒÔÔÚLinuxÖпÉÒÔÓÃFreeTDSÁ¬½ÓMS SQL¡£
ÎÒÃÇ¿ÉÒÔÀûÓÃOpenOffice.Org Base¼°Linux ODBCʵÏÖ¿ÉÊÓ»¯µÄÊý¾Ý¿â²é¿´·½Ê½¡£·½±ã¸öÈËÓû§Ê¹ÓÃLinuxÔ¶³Ì¹ÜÀí×Ô¼ºµÄÊý¾Ý¿âϵͳ¡£
ÃüÁîÐз½Ê½Ê¹Ó÷½·¨¼ò½é
°²×°FreeTDSºÍsqsh
Ê×ÏÈ°²×°FreeTDS£¬ÔÚDebian
/Ubuntu
ϵͳÖеݲװ¿ÉÒÔÖ±½Ó°²×°tdsodbc
ºÍsqsh
Èí¼þ°ü¡£Èç¹ûÄãʹÓõķ¢ÐаæûÓÐFreeTDS£¬¿ÉÒÔµ½FreeTDSµÄÍøÕ¾
ºÍsqshµÄÍøÕ¾
ÏÂÔØ°²×°¡£
ÏÖÔھͿÉÒÔÓÃsqsh·ÃÎÊSQL ServerÊý¾Ý¿âÁË£¬×î¼òµ¥µÄʹÓ÷½·¨ÈçÏ£º
sqsh -U Óû§Ãû -P ÃÜÂë -S ·þÎñÆ÷µØÖ·
µÈÒ»»á¶ùÈç¹û³öÏÖ1> £¬¾Í˵Ã÷Á¬½Ó³É¹¦ÁË£¬¿ÉÒÔÊÔ×ÅÊäÈëÈçÏÂÓï¾ä£º
SELECT @@version
go
×¢ÒâÊäÈëgoºó²ÅÖ´ÐÐÓï¾ä¡£
ͼÐνçÃæµÄÁ¬½Ó·½Ê½
°²×°Èí¼þ
ÇëÏÈ°²×°Ç°ÃæÃüÁîÐйÜÀí½çÃæ
ÖÐËù˵µÄFreeTDSºÍsqsh¡£È»ºó°²×°Èí¼þ°üunixodbc-bin
(Debian/Ubuntu)»òµ½unixODBCµÄÍøÕ¾
È¥ÏÂÔØ¡¢°²×°¡£
ÅäÖÃODBC
ÅäÖÃFreeTDS
FreeTDSµÄÅäÖÃÎļþÔÚ/etc/freetds/freetds.conf
£¨»òÕßÀàËƵĵط½£©¡£Óñ༭Æ÷´ò¿ªÕâ¸öÅäÖÃÎļþ£¨ÐèÒªrootȨÏÞ£©£¬²¢Ìí¼ÓÈçÏÂÄÚÈÝ£º
[myTDS]
......

mssqlÖÐÓÃxmlµÄ·½·¨²ð·ÖÒÔ²»¶¨¿Õ¸ñΪ·Ö¸î·ûºÅµÄ×Ö·û´®

---xml²ð·ÖÒÔ²»¶¨¿Õ¸ñΪ·Ö¸î·ûºÅµÄ×Ö·û´®
--²âÊÔÊý¾Ý
if object_id('[tb]') is not null drop table [tb]
create table [tb]([a] varchar(200))
go
insert [tb]
select 'aaaa  bbbb cccc        dddd'
insert [tb]
select 'eeeeee  ffff hhhh        yyyy                '
--¿ªÊ¼²éѯ
select
  rtrim(A.A) as a,B.A2
from (
  select a,convert(xml,'<root><row>'+replace(replace(rtrim(ltrim(a)),' ','</row><row>'),'<row></row>','')+'</row></root>') AS A1
  from [tb]
   ) a  outer apply (select a2=T.C.value('.','nvarchar(100)') from a.a1.nodes('/root/row')T(C)) B
/*
a                                &n ......

mssqlÖÐÓÃxmlµÄ·½·¨²ð·ÖÒÔ²»¶¨¿Õ¸ñΪ·Ö¸î·ûºÅµÄ×Ö·û´®

---xml²ð·ÖÒÔ²»¶¨¿Õ¸ñΪ·Ö¸î·ûºÅµÄ×Ö·û´®
--²âÊÔÊý¾Ý
if object_id('[tb]') is not null drop table [tb]
create table [tb]([a] varchar(200))
go
insert [tb]
select 'aaaa  bbbb cccc        dddd'
insert [tb]
select 'eeeeee  ffff hhhh        yyyy                '
--¿ªÊ¼²éѯ
select
  rtrim(A.A) as a,B.A2
from (
  select a,convert(xml,'<root><row>'+replace(replace(rtrim(ltrim(a)),' ','</row><row>'),'<row></row>','')+'</row></root>') AS A1
  from [tb]
   ) a  outer apply (select a2=T.C.value('.','nvarchar(100)') from a.a1.nodes('/root/row')T(C)) B
/*
a                                &n ......

Ö÷Á÷Êý¾Ý¿âMYSQL/MSSQL/ORACLE²âÊÔÊý¾Ý¿â½Å±¾´úÂë


/******************************************************************************/
/*
Ö÷Á÷Êý¾Ý¿âMYSQL/MSSQL/ORACLE²âÊÔÊý¾Ý¿â½Å±¾´úÂë
½Å±¾ÈÎÎñ:½¨Á¢4¸ö±í,Ìí¼ÓÖ÷¼ü,Íâ¼ü£¬²åÈëÊý¾Ý,½¨Á¢ÊÓͼ
ÔËÐл·¾³1:microsoft sqlserver 2000 ²éѯ·ÖÎöÆ÷
ÔËÐл·¾³2:mysql5.0 phpMyAdminÍøÒ³½çÃæ
ÔËÐл·¾³3:oracle 9i SQL*PLUSÃüÁîÐнçÃæ
author£ºchinayaosir
blog:   http://blog.csdn.net/chinayaosir/
QQ:    44633197
ÉùÃ÷£ºÑϽûÆäËüÍøÕ¾²»¾­¹ý×÷ÕßchinayaosirͬÒâÈÎÒâתÔØ
*/
/******************************************************************************/
/*script test ok with microsoft sqlserver 2000 ²éѯ·ÖÎöÆ÷ */
/******************************************************************************/
/*DB:MSSQL2000 SCRIPT*/
/*0.drop table list*/
    drop  table Employee;
    drop  table Department;
    drop  table Post;
    drop  table Account;
/*********************************************************/
/* ......

Ö÷Á÷Êý¾Ý¿âMYSQL/MSSQL/ORACLE²âÊÔÊý¾Ý¿â½Å±¾´úÂë


/******************************************************************************/
/*
Ö÷Á÷Êý¾Ý¿âMYSQL/MSSQL/ORACLE²âÊÔÊý¾Ý¿â½Å±¾´úÂë
½Å±¾ÈÎÎñ:½¨Á¢4¸ö±í,Ìí¼ÓÖ÷¼ü,Íâ¼ü£¬²åÈëÊý¾Ý,½¨Á¢ÊÓͼ
ÔËÐл·¾³1:microsoft sqlserver 2000 ²éѯ·ÖÎöÆ÷
ÔËÐл·¾³2:mysql5.0 phpMyAdminÍøÒ³½çÃæ
ÔËÐл·¾³3:oracle 9i SQL*PLUSÃüÁîÐнçÃæ
author£ºchinayaosir
blog:   http://blog.csdn.net/chinayaosir/
QQ:    44633197
ÉùÃ÷£ºÑϽûÆäËüÍøÕ¾²»¾­¹ý×÷ÕßchinayaosirͬÒâÈÎÒâתÔØ
*/
/******************************************************************************/
/*script test ok with microsoft sqlserver 2000 ²éѯ·ÖÎöÆ÷ */
/******************************************************************************/
/*DB:MSSQL2000 SCRIPT*/
/*0.drop table list*/
    drop  table Employee;
    drop  table Department;
    drop  table Post;
    drop  table Account;
/*********************************************************/
/* ......

Ö÷Á÷Êý¾Ý¿âMYSQL/MSSQL/ORACLE²âÊÔÊý¾Ý¿â½Å±¾´úÂë


/******************************************************************************/
/*
Ö÷Á÷Êý¾Ý¿âMYSQL/MSSQL/ORACLE²âÊÔÊý¾Ý¿â½Å±¾´úÂë
½Å±¾ÈÎÎñ:½¨Á¢4¸ö±í,Ìí¼ÓÖ÷¼ü,Íâ¼ü£¬²åÈëÊý¾Ý,½¨Á¢ÊÓͼ
ÔËÐл·¾³1:microsoft sqlserver 2000 ²éѯ·ÖÎöÆ÷
ÔËÐл·¾³2:mysql5.0 phpMyAdminÍøÒ³½çÃæ
ÔËÐл·¾³3:oracle 9i SQL*PLUSÃüÁîÐнçÃæ
author£ºchinayaosir
blog:   http://blog.csdn.net/chinayaosir/
QQ:    44633197
ÉùÃ÷£ºÑϽûÆäËüÍøÕ¾²»¾­¹ý×÷ÕßchinayaosirͬÒâÈÎÒâתÔØ
*/
/******************************************************************************/
/*script test ok with microsoft sqlserver 2000 ²éѯ·ÖÎöÆ÷ */
/******************************************************************************/
/*DB:MSSQL2000 SCRIPT*/
/*0.drop table list*/
    drop  table Employee;
    drop  table Department;
    drop  table Post;
    drop  table Account;
/*********************************************************/
/* ......
×ܼǼÊý:86; ×ÜÒ³Êý:15; ÿҳ6 Ìõ; Ê×Ò³ ÉÏÒ»Ò³ [2] [3] [4] [5] 6 [7] [8] [9] [10] [11]  ÏÂÒ»Ò³ βҳ
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ