ÈçºÎÕÒµ½sql serverÊý¾Ý¿âÖеÄËÀËø?
¼ì²âËÀËø
Èç¹û·¢ÉúËÀËøÁË£¬ÎÒÃÇÔõôȥ¼ì²â¾ßÌå·¢ÉúËÀËøµÄÊÇÄÄÌõSQLÓï¾ä»ò´æ´¢¹ý³Ì£¿
ÕâʱÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏ´洢¹ý³ÌÀ´¼ì²â£¬¾Í¿ÉÒÔ²é³öÒýÆðËÀËøµÄ½ø³ÌºÍSQLÓï¾ä¡£SQL Server×Ô´øµÄϵͳ´æ´¢¹ý³Ìsp_whoºÍsp_lockÒ²¿ÉÒÔÓÃÀ´²éÕÒ×èÈûºÍËÀËø, µ«Ã»ÓÐÕâÀï½éÉܵķ½·¨ºÃÓá£
use master
go
create procedure sp_who_lock
as
begin
declare @spid int,@bl int,
@intTransactionCountOnEntry int,
@intRowcount int,
@intCountProperties int,
@intCounter int
create table #tmp_lock_who (
id int identity(1,1),
spid smallint,
bl smallint)
IF @@ERROR<>0 RETURN @@ERROR
insert into #tmp_lock_who(spid,bl) select 0 ,blocked
from (select * from sysprocesses where blocked>0 ) a
where not exists(select * from (select * from sysprocesses where blocked>0 ) b
where a.blocked=spid)
union select spid,blocked from sysprocesses where blocked>0
IF @@ERROR<>0 RETURN @@ERROR
-- ÕÒµ½ÁÙʱ±íµÄ¼Ç¼Êý
select @intCountProperties = Count(*),@intCounter = 1
from #tmp_lock_who
IF @@ERROR<>0 RETURN @@ERROR
if @intCountProperties=0
select 'ÏÖÔÚûÓÐ×èÈûºÍËÀËøÐÅÏ¢' as message
-- Ñ»·¿ªÊ¼
while @intCounter <= @intCountProperties
begin
-- È¡µÚÒ»Ìõ¼Ç¼
select&nbs
Ïà¹ØÎĵµ£º
ÎÒÃÇÒª×öµ½²»µ«»áдSQL£¬»¹Òª×öµ½Ð´³öÐÔÄÜÓÅÁ¼µÄSQLÓï¾ä¡£
£¨1£©Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)£º
OracleµÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬from×Ó¾äÖÐдÔÚ×îºóµÄ±í(»ù´¡±í driving
table)½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏÂ,Äã±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í¡£È ......
Ç°Ìá,MS SQLµÄͨÅä·ûº¬Ò壺
ÐòºÅ
ͨÅä·û
º¬Òå
ʾÀý
1
%
°üº¬Áã¸ö»ò¶à¸ö×Ö·ûµÄÈÎÒâ×Ö·û´®¡£
WHERE title LIKE '%computer%' ½«²éÕÒÔÚÊéÃûÖÐÈÎÒâλÖðüº¬µ¥´Ê"computer" µÄËùÓÐÊéÃû¡£
2
_
Èκε¥¸ö×Ö·û¡£
WHERE au_fname LIKE '_ean' ½«²éÕÒÒÔ ean ½áβµÄËùÓÐ 4 ¸ö×ÖĸµÄÃû×Ö£¨Dean¡¢Sean µÈ£©¡£
3
[ ] ......
SQL ServerµÄÐÔÄÜÖ÷Ҫȡ¾öÓÚ´ÅÅÌI/OЧÂÊ£¬Ìá¸ßI/OЧÂÊijÖÖ³ÌÐòÉϾÍÒâζ×ÅÌá¸ßÐÔÄÜ¡£SQL Server 2008ÌṩÁËÊý¾ÝѹËõ¹¦ÄÜÀ´Ìá¸ß´ÅÅÌI/O¡£
Êý¾ÝѹËõÒâζ׿õСÊý¾ÝµÄÓдÅÅÌÕ¼ÓÃÁ¿£¬ËùÒÔÊý¾ÝѹËõ¿ÉÒÔÓÃÔÚ±í£¬¾Û¼¯Ë÷Òý£¬·Ç¾Û¼¯Ë÷Òý£¬ÊÓͼË÷Òý»òÊÇ·ÖÇø±í£¬·ÖÇøË÷ÒýÉÏ¡£
Êý¾ÝѹËõ¿ÉÒÔÔÚÁ½¸ö¼¶±ðÉÏʵÏÖ£ºÐ춱ðºÍÒ³¼¶±ð¡£Ò³¼¶±ðѹ ......
ÊÇÓÃÓÚ·ÃÎʺʹ¦ÀíÊý¾Ý¿âµÄ±ê×¼µÄ¼ÆËã»úÓïÑÔ¡£
ͨ¹ý SQL À´¹ÜÀíÊý¾Ý
½á¹¹»¯²éѯÓïÑÔ (SQL) ÊÇÓÃÓÚ·ÃÎÊÊý¾Ý¿âµÄ±ê×¼ÓïÑÔ£¬ÕâЩÊý¾Ý¿â°üÀ¨ SQL Server¡¢Oracle¡¢MySQL¡¢Sybase ÒÔ¼° Access µÈµÈ¡£
¶ÔÓÚÄÇЩϣÍûÔÚÊý¾Ý¿âÖд洢Êý¾Ý²¢´ÓÖлñÈ¡Êý¾ÝµÄÈËÀ´Ëµ£¬SQL µÄ֪ʶÊǼÛÖµÎÞ·¨ºâÁ¿µÄ¡£
ʲôÊÇ SQL?
SQL Ö¸½á¹¹»¯²éѯÓïÑÔ ......
use master
go
--Çл»masterÊý¾Ý¿â
if exists(select 1 from sysdatabases where name = N'test')
--×¢Òâ¸ÃͬÃûÊý¾Ý¿âÊÇ·ñ»¹ÒªÓõ½
begin
drop database test
end
go
create database test
on
primary
( name = 'testprimary', --Ö÷Êý¾ÝÎļþÂß¼Ãû
filename = 'D:\testprimary.mdf',--Ö÷Êý¾ÝÎļþ´æ·Å·¾¶
......