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

SQL Server±í·ÖÇø²Ù×÷Ïê½â

ÄãÊÇ·ñÔÚǧ·½°Ù¼ÆÓÅ»¯SQL Server Êý¾Ý¿âµÄÐÔÄÜ?Èç¹ûÄãµÄÊý¾Ý¿âÖк¬ÓдóÁ¿µÄ±í¸ñ£¬°ÑÕâЩ±í¸ñ·ÖÇø·ÅÈë¶ÀÁ¢µÄÎļþ×é¿ÉÄÜ»áÈÃÄãÊÜÒæ·Ëdz¡£SQL Server 2005ÒýÈëµÄ±í·ÖÇø¼¼Êõ£¬ÈÃÓû§Äܹ»°ÑÊý¾Ý·ÖÉ¢´æ·Åµ½²»Í¬µÄÎïÀí´ÅÅÌÖУ¬Ìá¸ßÕâЩ´ÅÅ̵IJ¢Ðд¦ÀíÐÔÄÜÒÔÓÅ»¯²éѯÐÔÄÜ¡£
¡¡¡¡SQL ServerÊý¾Ý¿â±í·ÖÇø²Ù×÷¹ý³ÌÓÉÈý¸ö²½Öè×é³É£º
¡¡¡¡1. ´´½¨·ÖÇøº¯Êý
¡¡¡¡2. ´´½¨·ÖÇø¼Ü¹¹
¡¡¡¡3. ¶Ô±í½øÐзÖÇø
¡¡¡¡ÏÂÃ潫¶Ôÿ¸ö²½Öè½øÐÐÏêϸ½éÉÜ¡£
¡¡¡¡²½ÖèÒ»£º´´½¨Ò»¸ö·ÖÇøº¯Êý
¡¡¡¡´Ë·ÖÇøº¯ÊýÓÃÓÚ¶¨ÒåÄãÏ£ÍûSQL ServerÈçºÎ¶ÔÊý¾Ý½øÐзÖÇøµÄ²ÎÊýÖµ([u]how[/u])¡£Õâ¸ö²Ù×÷²¢²»Éæ¼°Èκαí¸ñ£¬Ö»Êǵ¥´¿µÄ¶¨ÒåÁËÒ»Ïî¼¼ÊõÀ´·Ö¸îÊý¾Ý¡£
¡¡¡¡ÎÒÃÇ¿ÉÒÔͨ¹ýÖ¸¶¨Ã¿¸ö·ÖÇøµÄ±ß½çÌõ¼þÀ´¶¨Òå·ÖÇø¡£ÀýÈ磬¼Ù¶¨ÎÒÃÇÓÐÒ»·ÝCustomers±í£¬ÆäÖаüº¬Á˹ØÓÚËùÓпͻ§µÄÐÅÏ¢£¬ÒÔÒ»Ò»¶ÔÓ¦µÄ¿Í»§±àºÅ(´Ó1µ½1,000,000)À´Çø·Ö¡£ÎÒÃǽ«Í¨¹ýÒÔϵķÖÇøº¯Êý°ÑÕâ¸ö±í·ÖΪËĸö´óСÏàͬµÄ·ÖÇø£º¡¡¡¡
CREATE PARTITION FUNCTION customer_partfunc (int)
¡¡¡¡AS RANGE RIGHT
¡¡¡¡FOR VALUES (250000, 500000, 750000)
¡¡¡¡ÕâЩ±ß½çÖµ¶¨ÒåÁËËĸö·ÖÇø¡£µÚÒ»¸ö·ÖÇø°üÀ¨ËùÓÐֵСÓÚ250,000µÄÊý¾Ý£¬µÚ¶þ¸ö·ÖÇø°üÀ¨ÖµÔÚ250,000µ½49,999Ö®¼äµÄÊý¾Ý¡£µÚÈý¸ö·ÖÇø°üÀ¨ÖµÔÚ500,000µ½7499,999Ö®¼äµÄÊý¾Ý¡£ËùÓÐÖµ´óÓÚ»òµÈÓÚ750,000µÄÊý¾Ý±»¹éÈëµÚËĸö·ÖÇø¡£
¡¡¡¡Çë×¢Ò⣬ÕâÀïµ÷ÓõÄ"RANGE RIGHT"Óï¾ä±íÃ÷ÿ¸ö·ÖÇø±ß½çÖµÊÇÓҽ硣ÀàËƵģ¬Èç¹ûʹÓÃ"RANGE LEFT"Óï¾ä£¬ÔòÉÏÊöµÚÒ»¸ö·ÖÇøÓ¦¸Ã°üÀ¨ËùÓÐֵСÓÚ»òµÈÓÚ250,000µÄÊý¾Ý£¬µÚ¶þ¸ö·ÖÇøµÄÊý¾ÝÖµÔÚ250,001µ½500,000Ö®¼ä£¬ÒÔ´ËÀàÍÆ¡£
¡¡¡¡²½Öè¶þ£º´´½¨Ò»¸ö·ÖÇø¼Ü¹¹
¡¡¡¡Ò»µ©¸ø³öÃèÊöÈçºÎ·Ö¸îÊý¾ÝµÄ·ÖÇøº¯Êý£¬½ÓמÍÒª´´½¨Ò»¸ö·ÖÇø¼Ü¹¹£¬ÓÃÀ´¶¨Òå·ÖÇøλÖÃ([u]where[/u])¡£´´½¨¹ý³Ì·Ç³£Ö±½ØÁ˵±£¬Ö»Òª½«·ÖÇøÁ¬½Óµ½Ö¸¶¨µÄÎļþ×é¾ÍÐÐÁË¡£ÀýÈ磬Èç¹ûÓÐËĸöÎļþ×飬×éÃû´Ó"fg1"µ½"fg4"£¬ÄÇôÒÔϵķÖÇø¼Ü¹¹¾ÍÄÜ´ïµ½ÏëÒªµÄЧ¹û£º¡¡¡¡
CREATE PARTITION SCHEME customer_partscheme
¡¡¡¡AS PARTITION customer_partfunc
¡¡¡¡TO (fg1, fg2, fg3, fg4)
¡¡¡¡×¢Ò⣬ÕâÀォһ¸ö·ÖÇøº¯ÊýÁ¬½Óµ½Á˸÷ÖÇø¼Ü¹¹£¬µ«²¢Ã»Óн«·ÖÇø¼Ü¹¹Á¬½Óµ½ÈκÎÊý¾Ý±í¡£Õâ¾ÍÊǿɸ´ÓÃÐÔÆð×÷Óõĵط½ÁË¡£ÎÞÂÛÓжàÉÙÊý¾Ý¿â±í£¬ÎÒÃǶ¼¿ÉÒÔʹÓø÷ÖÇø¼Ü¹¹(»ò½ö½öÊÇ·ÖÇøº¯Êý)¡£
¡¡¡¡²½ÖèÈý£º¶ÔÒ»¸ö


Ïà¹ØÎĵµ£º

SQL´æ´¢¹ý³Ì·ÖÒ³Ëã·¨Ñо¿(Ö§³ÖǧÍò¼¶)

SQL´æ´¢¹ý³Ì·ÖÒ³Ëã·¨Ñо¿(Ö§³ÖǧÍò¼¶)
1.“¶íÂÞ˹´æ´¢¹ý³Ì”µÄ¸ÄÁ¼°æ
CREATE procedure pagination1
(@pagesize int, --Ò³Ãæ´óС£¬Èçÿҳ´æ´¢20Ìõ¼Ç¼
@pageindex int --µ±Ç°Ò³Âë)
as set nocount on
begin
declare @indextable table(id int identity(1,1),nid int) --¶¨Òå±í±äÁ¿
declare @PageL ......

SQLÖÐIN,NOT IN,EXISTS,NOT EXISTSµÄÓ÷¨ºÍ²î±ð


SQLÖÐIN,NOT IN,EXISTS,NOT EXISTSµÄÓ÷¨ºÍ²î±ð:
IN:È·¶¨¸ø¶¨µÄÖµÊÇ·ñÓë×Ó²éѯ»òÁбíÖеÄÖµÏàÆ¥Åä¡£
IN ¹Ø¼ü×ÖʹÄúµÃÒÔÑ¡ÔñÓëÁбíÖеÄÈÎÒâÒ»¸öֵƥÅäµÄÐС£
µ±Òª»ñµÃ¾ÓסÔÚ California¡¢Indiana »ò Maryland ÖݵÄËùÓÐ×÷ÕßµÄÐÕÃûºÍÖݵÄÁбíʱ£¬¾ÍÐèÒªÏÂÁвéѯ£º
SELECT ProductID, ProductName from Northwind.dbo.Pro ......

½«±íÊý¾ÝÉú³ÉSQL½Å±¾µÄ´æ´¢¹ý³Ì

CREATE PROCEDURE dbo.UspOutputData
@tablename sysname
AS
declare @column varchar(1000)
declare @columndata varchar(1000)
declare @sql varchar(4000)
declare @xtype tinyint
declare @name sysname
declare @objectId int
declare @objectname sysname
declare @ident int
set nocount on ......

±È½ÏÁ½¸öSQLµÄÖ´ÐÐʱ¼ä

±È½ÏÁ½¸öSQLµÄÖ´ÐÐʱ¼ä
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PROC_SQL_COMP]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[PROC_SQL_COMP]
GO
/*--²âÊÔÁ½×éSQLµÄƽ¾ùʱ¼ä
 
 ÀûÓÃosql.exeÀ´²âÊÔÁ½×é SQL Óï¾äµÄÖ´ÐÐʱ¼ä
 ²âÊԵĴ洢¹ý³ ......

SQL½»²æ±í²éѯ ÈçºÎʵÏÖ

Çë½Ì´ó¼ÒÒ»¸öÓйØSQL½»×¤±¨±í²éѯÎÊÌ⣬»¶Ó­¸÷λָ½Ì£¡
ÎÒÏë°Ñͼ1µÄʹÓÃÐÅÏ¢£¬Ê¹ÓÃSQLÓï¾ä£¬ÊµÏÖÈçͼ2µÄ½á¹û¡£
±íÃû
ÐòºÅ
×Ö¶ÎÃû
a
1
c
a
2
d
a
3
e
a
4
f
a
5
g
b
1
h
b
2
i
b
3
j
b
4
k
b
5
l
c
1
m
c
2
n
c
3
o
c
4
p
c
5
q
ͼ1
 
±íÃû
ÐòºÅ
1
2
3
4
5 ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ