[SQL Server]SQLServer ÅúÁ¿²åÈëÊý¾ÝµÄÁ½ÖÖ·½·¨
ÔÚ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();
}
Console.ReadLine();
ºÄʱͼÈçÏ£º
ÓÉÓÚÔËÐйýÂý£¬²Å²åÈë10ÍòÌõ
Ïà¹ØÎĵµ£º
Èç¹ûÏë²éÕÒ“_cs”½áβµÄµÄÕË»§
select * from [user] where loginname like '%_cs'ÊDz»Ðеģ¬_ ±»ÈÏΪÊÇÈÎÒâµÄ×Ö·û£¬
ËùÒÔÐèҪתÒå×Ö·û£¬ÓÐÁ½ÖÖд·¨£º
select * from [user] where loginname like '%[_]cs'
select * from [user] where loginname like '%/_cs' escape'/'
ͨÅä·ûº¬Òå
%
°üº¬Áã¸ö»ò¸ü¶à×Ö· ......
µ÷ÊÔSQLÊý¾Ý£¬·¢ÏÖÊý¾Ý¼Ç¼¼¯Öظ´ÎÊÌ⣬ËùÒÔ£¬¼ÆËã³öµÄÊý¾Ý½á¹û±¶ÊýÎÊÌ⡣ͨ¹ýµ÷ÊÔSQL£¬·¢ÏÖÊÇÎïÁϵķÖÀà²úÉúÖظ´£»Ö®ËùÒÔ²úÉúÖظ´£¬ÎïÁϵķÖÀà±ê×¼²»Ò»Ñù£¬Óëʵ¼ÊµÄÒµÎñÓйء£³ÌÐòÖÐÒ»Ö±ÓÃÀà±ðÀ´Çø·ÖÀà±ð£¬¶øÕâÕÅ´Îʵ¼ÊÒµÎñ²»ÐèÒªÓëÀà±ðÓйأ¬ËùÒÔ£¬Ã»ÓжÔÓ¦µÄ¹ýÂËÌõ¼þ£¬ËùÓеÄÀà±ðÈ«²¿Ñ¡³öÀ´ÁË¡£È»ºó£¬°ÑÏÂÃæµÄºìÉ«×Ö¶Î×¢ ......
±¾ÎÄתÔØÓÚ£ºhttp://www.javaeye.com/topic/185385
ѧϰÊý¾Ý¿â²éѯµÄʱºò¶Ô¶à±íÁ¬½Ó²éѯµÄÓÐЩ¸ÅÄ±È½ÏÄ£ºý¡£¶øÁ¬½Ó²éѯÊÇÔÚÊý¾Ý¿â²éѯ²Ù×÷µÄʱºò¿Ï¶¨ÒªÓõ½µÄ¡£¶ÔÓڴ˸ÅÄî
ÎÒÓÃͨË×һЩµÄÓïÑÔºÍÀý×ÓÀ´½øÐн²½â¡£Õâ¸öÀý×ÓÊÇÎÒ½²¿ÎµÄʱºò¾³£²ÉÓõÄÀý×Ó¡£
Ê×ÏÈÎÒÃÇ×öÁ½ÕÅ±í£ºÔ±¹¤ÐÅÏ¢±íºÍ²¿ÃÅÐÅÏ¢±í£¬ÔÚ´Ë£¬±íµ ......
¾¹ýÁ˼¸´ÎµÄ²âÊÔÖÕÓڳɹ¦ÁË
declare @Year Int,
@Month int,
@Day int,
@Temp_No varchar(12),
@NeedNo varchar(4),
......
ǰһƪ²©¿Í IP to Integer ÌṩµÄ SQL º¯ÊýÊÇ IP ת»»³É Integer µÄ·½·¨¡£ Integer µÄ×î´óֵΪ£º 2147483647£¨2^31 - 1£©¡£°´ÕÕ IP ת»»³ÉÕûÊýµÄËã·¨£¬»áËã³öÀ´´óÓÚÕâ¸öÖµµÄ£¬ËùÒÔ֮ǰÌṩµÄ IP ת»»³É Integer µÄ·½·¨»áËã³ö¸ºÖµ¡£ ÏÂÃæÊÇ IP to BigInt µÄת»»Ëã·¨£¬ ÕâʱºòÔËËã¾Í²»»áСÓÚÁã¡£
CREATE FUNCTION dbo.ipS ......