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

SQL³£¼û²éѯÎÊÌâ(±à³Ì)


ÓÐЩ³£¼ûµÄÎÊÌâÔÚÂÛ̳Öв»¶Ï³öÏÖ£¬²»·ÁÕûÀíһϡ£
ÒÔÏÂÓï¾äÊÇÔÚSQLServer2005ÉÏʵÏֵģ¬Ò»Ð©Óï¾äÎÞ·¨ÔÚSS2000ÉÏÖ´ÐС£
ÓÐÓÃÖ¸ÊýÊÇÎÒ¸ù¾ÝÕâ¸öÎÊÌâµÄ³£¼û³Ì¶È´òµÄ·Ö£¬½ö¹©²Î¿¼¡£Êµ¼ÊÉÏ£¬µ±ÄãÓöµ½ÁËÕâ¸öÎÊÌ⣬Õâ¸öÎÊÌâÄÄÅÂÔÙÉÙ¼û£¬½â¾ö·½°¸Ò²ÊǷdz£ÓÐÓõġ£
1. Éú³ÉÈô¸ÉÐмǼ
ÓÐÓÃÖ¸Êý£º¡ï¡ï¡ï¡ï¡ï
³£¼ûµÄÎÊÌâÀàÐÍ£º¸ù¾ÝÆðÖ¹ÈÕÆÚÉú³ÉÈô¸É¸öÈÕÆÚ¡¢Éú³ÉÒ»ÌìÖеĸ÷¸öʱ¼ä¶Î
¡¶SQL Server 2005¼¼ÊõÄÚÄ»£ºT-SQL²éѯ¡·×÷Õß½¨ÒéÔÚÊý¾Ý¿âÖд´½¨Ò»¸öÊý¾Ý±í£º
SQL code
--×ÔÈ»Êý±í1-1M
CREATE TABLE Nums(n int NOT NULL PRIMARY KEY CLUSTERED)
--ÊéÉϽéÉÜÁ˺ܶàÖÖÌî³ä·½·¨£¬ÒÔÏÂÊÇ×î¸ßЧµÄÒ»ÖÖ£¬ÐèÒªSS2005µÄROW_NUMBER()º¯Êý¡£
WITH B1 AS(SELECT n=1 UNION ALL SELECT n=1), --2
B2 AS(SELECT n=1 from B1 a CROSS JOIN B1 b), --4
B3 AS(SELECT n=1 from B2 a CROSS JOIN B2 b), --16
B4 AS(SELECT n=1 from B3 a CROSS JOIN B3 b), --256
B5 AS(SELECT n=1 from B4 a CROSS JOIN B4 b), --65536
CTE AS(SELECT r=ROW_NUMBER() OVER(ORDER BY (SELECT 1)) from B5 a CROSS JOIN B3 b) --65536 * 16
INSERT INTO Nums(n)
SELECT TOP(1000000) r from CTE ORDER BY r
ÓÐÁËÕâ¸öÊý×Ö±í£¬¿ÉÒÔ×öºÜ¶àÊÂÇ飬³ýÉÏÃæÌáµ½µÄÁ½¸öÍ⣬»¹ÓУºÉú³ÉÒ»Åú²âÊÔÊý¾Ý¡¢Éú³ÉËùÓÐASCII×Ö·û»òUNICODEÖÐÎÄ×Ö·û¡¢µÈµÈ¡£
¾­³£ÓиßÊÖʹÓÃSELECT number from master..spt_values WHERE type = 'P'£¬ÕâÊǺÜÃîµÄ·½·¨£»µ«ÕâÑùÖ»ÓÐ2048¸öÊý×Ö£¬¶øÇÒÓï¾äÌ«³¤£¬²»¹»·½±ã¡£
×ÜÖ®£¬Ò»¸öÊý×Ö¸¨Öú±í£¨10Íò»¹ÊÇ100Íò¸ù¾Ý¸öÈËÐèÒª¶ø¶¨£©£¬ÄãÖµµÃÓµÓС£
-------------------------------------------------------------------------------
2. ÈÕÀú±í
ÓÐÓÃÖ¸Êý£º¡ï¡ï¡ï¡î¡î
¡¶SQL±à³Ì·ç¸ñ¡·Ò»Ê齨ÒéÒ»¸öÆóÒµµÄÊý¾Ý¿âÓ¦¸Ã´´½¨Ò»¸öÈÕÀú±í£º
SQL code
CREATE TABLE Calendar(
date datetime NOT NULL PRIMARY KEY CLUSTERED,
weeknum int NOT NULL,
weekday int NOT NULL,
weekday_desc nchar(3) NOT NULL,
is_workday bit NOT NULL,
is_weekend bit NOT NULL
)
GO
WITH CTE1 AS(
SELECT
date = DATEADD(day,n,'19991231')
from Nums
WHERE n <= DATEDIFF(day,'19991231','20201231')),
CTE2 AS(
SELECT
date,
weeknum = DATEPART(week,date),
weekday = (DATEPART(weekday,


Ïà¹ØÎĵµ£º

½â¾öÊý¾ÝÄÚÓÐ'µÄsqlÓï¾ä

SELECT OrderId, TableName, replace(PrimaryKeyColumn,'''','''''') as PrimaryKeyColumn, ColumnState,cast(IsUpdating as varchar) as IsUpdating, OperateTime, ValueColumn, SystemTypeID from SubCompFtpDataDairy where OperateTime>=dateadd(hh,-24,getdate()) ......

Sql NewId() Ëæ»úÊý £¨×ª£©


´ÓA±íËæ»úÈ¡10Ìõ¼Ç¼,ÓÃSELECT TOP 10 * from ywle order by newid()
order by Ò»°ãÊǸù¾Ýijһ×Ö¶ÎÅÅÐò,newid()µÄ·µ»ØÖµ ÊÇuniqueidentifier ,order by newid()Ëæ»úÑ¡È¡¼Ç¼ÊÇÈçºÎ½øÐеÄ
newid()ÔÚɨÃèÿÌõ¼Ç¼µÄʱºò¶¼Éú³ÉÒ»¸öÖµ, ¶øÉú³ÉµÄÖµÊÇËæ»úµÄ, ûÓдóСд˳Ðò. ËùÒÔ×îÖÕ½á¹ûÔÙ°´Õâ¸öÅÅÐò, ÅÅÐòµÄ½á¹ûµ±È»¾ÍÊÇÎ ......

hibernate ¶àÌõ¼þ×éºÏ²éѯ Ö® sql Æ´½Ó

  public static void main(String[] args) {
      
       Session session = null;
       Transaction tx = null;
       List list = null;
     &nb ......

asp.netµÄsql·À×¢Èë


/// <summary>
    /// ¹ýÂ˱ê¼Ç
    /// </summary>
    /// <param name="NoHTML">°üÀ¨HTML£¬½Å±¾£¬Êý¾Ý¿â¹Ø¼ü×Ö£¬ÌØÊâ×Ö·ûµÄÔ´Âë </param>
    /// <returns>ÒѾ­È¥³ý±ê¼ÇºóµÄÎÄ×Ö</returns>
  &nbs ......

sql serverÖн«×ÔÔö³¤ÁйéÁã

Ò»¸öÏîÄ¿Íê³ÉºóÊý¾Ý¿âÖлáÓкܶàÎÞÓõIJâÊÔÊý¾Ý£¬¿ÉÒÔʹÓÃdelete * ½«Êý¾ÝÈ«²¿É¾³ý£¬µ«×ÔÔö³¤ÁУ¨Ò»°ãÊÇÖ÷¼ü£©»ùÊý²»»á¹éÁ㣬ʹÓÃTRUNCATEº¯Êý¿ÉÒÔ½«±íÖÐÊý¾ÝÈ«²¿É¾³ý£¬²¢ÇÒ½«×ÔÔö³¤ÁлùÊý¹éÁã¡£Ò»¶¨Òª×¢Ò⣬±íÖеÄÊý¾ÝÈ«²¿É¾³ýÁË¡£ËüµÄÓï·¨ÈçÏ£º
TRUNCATE TABLE tableName –ÆäÖÐtableNameÖÐËùÒª²Ù×÷µÄÊý¾Ý
......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ