ÉîÈëÑо¿SQL SERVER 2005ºÍ¶à»î¶¯½á¹û¼¯£¨MARS£©
SQL SERVER 2005ÒýÈëÁËÔÚµ¥Ò»Á¬½ÓÉ϶Զà»î¶¯½á¹û¼¯£¨Ò²³ÆΪMARS£©»ò¶à¸öÇëÇóµÄÖ§³Ö¡£Í¨¹ýÔÚÓëSQL SERVER 2005µÄÁ¬½ÓÉÏÆôÓÃÕâÒ»ÌØÐÔ£¬µ±´æÔÚÓëSqlconnectionÏà¹ØÁªµÄ¿ª·ÅʽSqlDataReaderʱ£¬Á¬½Ó½«²»»áÖжϡ£¼´Ê¹ÉÐδ¹Ø±Õµ±Ç°´ò¿ªµÄSqlDataReader£¬Ò²ÈÔÈ»Äܹ»ÔÚSqlconnectionÉÏÖ´ÐÐÆäËû²éѯ±ÈÈ磺SELECT£¬UPDATE£¬CREATETABLEµÈµÈ¡£
¾Ù¸ö¼òµ¥µÄÀý×Ó£¬¾ÍÊÇÔÚNorthwindÊý¾Ý¿âÀïµÄ¶©µ¥±íÀïÈ¡¶©µ¥Êý¾Ý£¬¶øÇҰѶÔÓ¦µÄ×Ó¶©µ¥Ã÷ϸÊý¾ÝÒ»ÆðÈ¡³ö¡£
C#ʾÀý´úÂ룺<¼¤¹â´«Õæ»ú>
string strSQL;
SqlConnectionStringBuilder ssb = new SqlConnectionStringBuilder();
ssb.DataSource = ".";
ssb.InitialCatalog = "Northwind";
ssb.UserID = "sa";
ssb.Password = "********";
ssb.MultipleActiveResultSets = true;
SqlConnection cn = new SqlConnection(ssb.ConnectionString);
SqlCommand cmdOrders, cmdDetials;
SqlParameter pCustID, pOrderID;
SqlDataReader rdrOrders, rdrDetials;
cn.Open();
strSQL = "SELECT OrderID,OrderDate from Orders WHERE CustomerID = @CustomerID";
cmdOrders = new SqlCommand(strSQL, cn);
pCustID = cmdOrders.Parameters.Add("@CustomerID", SqlDbType.NChar, 5);
strSQL = "SELECT ProductID,Quantity,UnitPrice from [ORDER dETAiLS] WHERE OrderID = @OrderID";
cmdDetials = new SqlCommand(strSQL, cn);
pOrderID = cmdDetials.Parameters.Add("@OrderID", SqlDbType.NChar, 5);
pCustID.Value = "ALFKI";
Console.WriteLine("Orders for {0}", pCustID.Value);
Console.WriteLine("=================");
rdrOrders = cmdOrders.ExecuteReader();
while (rdrOrders.Read())
{
Console.WriteLine("OrderID: {0} OrderDate:{1:d}", rdrOrders["OrderID"], rdrOrders["OrderDate"]);
pOrderID.Value = rdrOrders["OrderID"];
rdrDetials = cmdDetials.ExecuteReader();
while (rdrDetials.Read())
Ïà¹ØÎĵµ£º
2009-11-18 12:51:46
ÏÞ¶¨´¦Àí¼Ç¼µÄµ¥Î»£¬rowcount=100±íʽÿ´Î´¦Àí100ÌõÊý¾Ý¡£Êµ¼Ê´¦ÀíµÄ¼Ç¼ÊýÓÉrowcountºÍwhere×Ó¾ä¾ö¶¨¡£Èç¹û·ûºÏwhereµÄ¼Ç¼Êý´óÓÚrowcount,ÔòÓÐrowcount¾ö¶¨£¬Èç¹ûСÓÚrowcount£¬ÔòÓÉwhere¾ö¶¨¡£
create table tb(id int identity(1,1),num int)
insert into tb
values(1)
while @@ ......
[C#]
public void RunSqlTransaction(string myConnString)
{
SqlConnection myConnection = new SqlConnection(myConnString);
myConnection.Open();
SqlCommand myCommand = myConnection.CreateCommand();
SqlTransaction m ......
declare @i int
set @i=1
while @i<30
begin
insert into test (userid) values(@i)
set @i=@i+1
end
---------------
while Ìõ¼þ
begin
Ö´ÐвÙ×÷
set @i=@i+1
end
WHILE
ÉèÖÃÖظ´Ö´ÐÐ SQL Óï¾ä»òÓï¾ä¿éµÄÌõ¼þ¡£Ö»ÒªÖ¸¶¨µÄÌõ¼þΪÕ棬¾ÍÖظ´Ö´ÐÐÓï¾ä¡£¿ÉÒÔʹÓà BREAK ºÍ CONTINUE ¹Ø¼ü×ÖÔÚÑ»·ÄÚ²¿¿ ......
/*ͳ¼ÆÿÌìÊý¾Ý×ÜÁ¿ÈýÖÖ·½·¨£º
select convert(char(10),happentime ,120) as date ,count(1) from table1
group by convert(char(10),happentime ,120) order by date desc
s ......