Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

SQLServer ÅúÁ¿²åÈëÊý¾ÝµÄÁ½ÖÖ·½·¨

SQLServer ÅúÁ¿²åÈëÊý¾ÝµÄÁ½ÖÖ·½·¨
2009-07-27 19:31
ÔÚSQL Server ÖвåÈëÒ»ÌõÊý¾ÝʹÓÃInsertÓï¾ä£¬µ«ÊÇÈç¹ûÏëÒªÅúÁ¿²åÈëÒ»¶ÑÊý¾ÝµÄ»°£¬Ñ­»·Ê¹ÓÃInsert²»½öЧÂʵͣ¬¶øÇһᵼÖÂSQLһϵͳÐÔÄÜÎÊÌâ¡£ÏÂÃæ½éÉÜSQL ServerÖ§³ÖµÄÁ½ÖÖÅúÁ¿Êý¾Ý²åÈë·½·¨£ºBulkºÍ±íÖµ²ÎÊý(Table-Valued Parameters)¡£
       ÔËÐÐÏÂÃæµÄ½Å±¾£¬½¨Á¢²âÊÔÊý¾Ý¿âºÍ±íÖµ²ÎÊý¡£
´úÂëÈçÏÂ:
--Create DataBase
create database BulkTestDB;
go
use BulkTestDB;
go
--Create Table
Create table BulkTestTable(
Id int primary key,
UserName nvarchar(32),
Pwd varchar(16))
go
--Create Table Valued
CREATE TYPE BulkUdt AS TABLE
(Id int,
UserName nvarchar(32),
Pwd varchar(16))
ÏÂÃæÎÒÃÇʹÓÃ×î¼òµ¥µÄInsertÓï¾äÀ´²åÈë100ÍòÌõÊý¾Ý£¬´úÂëÈçÏ£º
´úÂëÈçÏÂ:
Stopwatch sw = new Stopwatch();
SqlConnection sqlConn = new SqlConnection(
ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);//Á¬½ÓÊý¾Ý¿â
SqlCommand sqlComm = new SqlCommand();
sqlComm.CommandText = string.Format("insert into BulkTestTable(Id,UserName,Pwd)values(@p0,@p1,@p2)");//²ÎÊý»¯SQL
sqlComm.Parameters.Add("@p0", SqlDbType.Int);
sqlComm.Parameters.Add("@p1", SqlDbType.NVarChar);
sqlComm.Parameters.Add("@p2", SqlDbType.VarChar);
sqlComm.CommandType = CommandType.Text;
sqlComm.Connection = sqlConn;
sqlConn.Open();
try
{
//Ñ­»·²åÈë100ÍòÌõÊý¾Ý£¬Ã¿´Î²åÈë10ÍòÌõ£¬²åÈë10´Î¡£
for (int multiply = 0; multiply < 10; multiply++)
{
for (int count = multiply * 100000; count < (multiply + 1) * 100000; count++)
{
sqlComm.Parameters["@p0"].Value = count;
sqlComm.Parameters["@p1"].Value = string.Format("User-{0}", count * multiply);
sqlComm.Parameters["@p2"].Value = string.Format("Pwd-{0}", count * multiply);
sw.Start();
sqlComm.ExecuteNonQuery();
sw.Stop();
}
//ÿ²åÈë10ÍòÌõÊý¾Ýºó£¬ÏÔʾ´Ë´Î²åÈëËùÓÃʱ¼ä
Console.WriteLine(string.Format("Elapsed Time is {0} Milliseconds", sw.ElapsedMilliseconds));
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
sqlConn.Close();


Ïà¹ØÎĵµ£º

sqlserver µÄprepare·½·¨Ê¹ÓÃÎÊÌâ

1.Èç¹ûÏÈprepare ºóÌí¼Ó²ÎÊý£¬ÕâÑùÒ»²¿·ÖÊý¾ÝÀàÐÍ¿ÉÒÔ²»ÓÃÉèÖÃÆäsize´óС£¬ÀýÈçchar
2.Èç¹ûÏÈÌí¼Ó²ÎÊýÔÙprepare£¬¾Í±ØÐëÉèÖòÎÊýµÄÀàÐÍ£¬´óС£¬¾«¶È²ÅÄÜͨ¹ý£¬±ÈÈçchar,varchar,decimalÀàÐÍ£¬¶øint,floatÓй̶¨×Ö½ÚÀàÐ͵ÄÊý¾ÝÀàÐÍÔò¿É²»ÓÃÉèÖôóС¡£
3.¹ØÓÚSqlServerµÄtimestampÀàÐÍ£º¸ÃÀàÐÍΪSqlServerµÄʱ¼ä´ÁÀàÐÍ£¬´´½ ......

sqlserverÁ´½Ó·þÎñÆ÷ʹÓ÷½·¨

EXEC sp_addlinkedsrvlogin @rmtsrvname = 'serverontest', @useself = 'false', @locallogin = 'sa', @rmtuser = 'sa', @rmtpassword = 'passwordofsa'
Ìí¼ÓµÇ¼·½Ê½
ÒÔÉÏÁ½¸öÓï¾äÖУ¬@serverΪ·þÎñÆ÷µÄ±ðÃû£¬@datasrcΪҪÁ´½ÓµÄÄ¿±êÊý¾Ý¿âµÄÁ¬½Ó´®£¬@rmtsrvnameΪ±ðÃû,@localloginΪ±¾µØµÇ¼µÄÓû§Ãû£¬@rmtuserºÍ@rmtpa ......

Flex+JavaÁ¬½ÓSQLServerÊý¾Ý¿â

Ê×ÏÈ£¬×öÒ»µã˵Ã÷¡£FlexÊDz»ÄÜÖ±½ÓÁ¬½ÓÊý¾Ý¿âµÄ£¬ÕâÒ»µã´ó¼ÒÐèÒªÖªµÀ£¬ËüÖ»Äܼä½ÓµØÁ¬½ÓÊý¾Ý¿â¡£FlexÖÐÌṩÁËÈýÖÖ·½Ê½£ºHttpService£¬WebService ºÍRemoteObject¡£ÆäÖÐHttpService¿ÉÒÔÖ±½Ó»ñÈ¡XMLÖеÄÊý¾Ý£¬»¹¿ÉÒÔͨ¹ýJSP,ASPÒÔ¼°PHP¶ÁÈ¡Êý¾Ý¿âÖеÄÊý¾Ý£¬Õâ¸ö±È½Ï¼òµ¥£¬¶øÇÒÍøÉÏÒ²ÓкܶàÀý×Ó£¬ÎҾͲ»¶à˵ÁË¡£WebServiceÎÒ²» ......

SQLServerÖжÔËùÓеÄÓû§±íÉú³É´¥·¢Æ÷

²âÊÔµÄʱºò±È½ÏÖØÒª£¬ÎÒÃÇ¿ÉÒÔÖªµÀµ±Ç°½»Ò×Ó°ÏìÁËÄÄЩ±í
--ÓÃÓڼǼÓû§ÔÚµ±Ç°±íÉÏʲôʱºò¡¢×öµÄʲô²Ù×÷£ºupdate¡¢insert¡¢delete
create table TriggerRecord
(
 operdt datetime, --´¥·¢Ê±¼ä
 opertp varchar(10), --²Ù×÷ÀàÐÍ£ºupdate¡¢insert¡¢delete
 opertb varchar(50) --±íÃû ......

SQLServer½«ÈÕÆÚת»»³É×Ö·û´®¸ñʽ

 SELECT   convert(char,ÈÕÆÚ×Ö¶Î,120)   as   date2   from   table
mssqlĬÈÏÒÔϵͳʱ¼ä¸ñʽÊä³ö£¬Äã¿ÉÒÔµ÷ÕûϵͳµÄʱ¼ä¸ñʽÀ´½â¾ö
µ±È»ÊÇÔÚ³ÌÐòÀï½â¾ö±È½ÏÁé»î£¬convert(char,date,N)Êä³öµÄ¸÷ÖÖÑùʽ
N   ÈÕÆÚÑùʽ  
0   04& ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ