sqlserver »ù´¡ÖªÊ¶´óÕûÀí
SQL-Structured Query Language
--(¿ªÆôSQL·þÎñ£ºnet start mssqlserver)
--(ÔÚÃüÁîÐÐÖÐÊäÈë'sqlwb'ÃüÁî¿É´ò¿ªSQL¹ÜÀíÆ÷ )
--(Èç¹ûÒªÖ´ÐжàÌõÃüÁîÖеÄÒ»Ìõ,Êó±êÑ¡¶¨ºóÔÙ°´F5Ö´ÐÐ)
create database sales --´´½¨Ò»¸öÃûΪsalesµÄÊý¾Ý¿â
on
(
name='sales_data',
filename='d:\sales_data.mdf',
size=10,
maxsize=50,
filegrowth=5
)
log on
(
name='sales_log',
filename='d:\sales_log.ldf',
size=10,
maxsize=50,
filegrowth=5
)
drop database sales --ɾ³ýËù´´½¨µÄÊý¾Ý¿â
sp_helpdb sales --²é¿´Êý¾Ý¿âµÄÏà¹ØÐÅÏ¢
sp_helpfile --²é¿´µ±Ç°Êý¾Ý¿âÊý¾ÝÎļþÓëÈÕÖ¾ÎļþµÄÏà¹ØÐÅÏ¢
sp_detach_db sales --תÒÆÊý¾Ý¿âʱ·ÖÀëÊý¾Ý¿â
sp_attach_db sales,@filename1='Êý¾ÝÎļþ·¾¶Ãû' --ÕûºÏ·ÖÀëµÄÊý¾Ý¿â
,@filename2='ÈÕÖ¾Îļþ·¾¶Ãû'
--(ÈçºÎ¼õСÊý¾Ý¿âÈÕÖ¾ÎļþµÄ´óС: a.·ÖÀëÊý¾Ý¿â b.תÒÆÈÕÖ¾Îļþ c .ÕûºÏÊý¾Ý¿âµ«²»Ö¸¶¨ÈÕÖ¾Îļþ)
--Êý¾Ý¿âµÄ±¸·Ý
sp_addumpdevice 'disk','mydisk','d:\sales.bak' --Ìí¼ÓÉ豸¡£disk±íʾĿ±êÉ豸ÀàÐÍ,mydisk±íʾĿ±êÉ豸Âß¼Ãû³Æ,d:\sales.bak±íʾĿ±êÉ豸ÎïÀíÃû³Æ
backup database sales to mydisk --ÏòÉ豸дÈëÊý¾Ý.ÆäÖеÄsalesÖ¸Êý¾Ý¿âÃû,mydiskΪ×Ô¶¨µÄÉ豸±êʾ·û
restore database sales from mydisk --»Ö¸´Êý¾Ý¿â
sp_dropdevice mydisk --ɾ³ýÉ豸
EXEC sp_dboption 'sales','read only','true' --ÉèÊý¾Ý¿âΪֻ¶Á
EXEC sp_dboption 'sales',autoshrink,true --ÉèÊý¾Ý¿âΪ×Ô¶¯Ñ¹Ëõ
EXEC sp_dboption 'sales','single user' --ÉèÊý¾Ý¿âΪµ¥Óû§
--(ÒÔÉÏÃüÁîÖе¥ÒýºÅ¿É¼Ó¿É²»¼Ó,µ«Ãû×ÖÖгöÏÖ¿Õ¸ñµÄÒ»¶¨Òª¼Ó.´óСд²»·Ö)
DBCC shrinkdatabase (sales,10) --½«Êý¾Ý¿âÖеÄÎļþ¼õС,ʹÊý¾Ý¿âÖÐÓÐ10%µÄ¿ÉÓÿռä
---------------------------------------------------------------------------------------------------------------
create table goods --½¨±íµÄµÚÒ»ÖÖÔ¼ÊøÓï·¨
(
gid int primary key,
gname varch
Ïà¹ØÎĵµ£º
SQLServer2005·Ö½â²¢µ¼ÈëxmlÎļþ ÊÕ²Ø
²âÊÔ»·¾³SQL2005£¬windows2003
DECLARE @idoc int;
DECLARE @doc xml;
SELECT @doc=bulkcolumn from OPENROWSET(
BULK 'D: \test.xml',
SINGLE_BLOB) AS x
EXEC sp_xml_preparedocument @Idoc OUTPUT, @doc
......
HOLDLOCK ½«¹²ÏíËø±£Áôµ½ÊÂÎñÍê³É£¬¶ø²»ÊÇÔÚÏàÓ¦µÄ±í¡¢ÐлòÊý¾ÝÒ³²»ÔÙÐèҪʱ¾ÍÁ¢¼´ÊÍ·ÅËø¡£HOLDLOCK µÈͬÓÚ SERIALIZABLE¡£
NOLOCK ²»Òª·¢³ö¹²ÏíËø£¬²¢ÇÒ²»ÒªÌṩÅÅËüËø¡£µ±´ËÑ¡ÏîÉúЧʱ£¬¿ÉÄÜ»á¶ÁȡδÌá½»µÄÊÂÎñ»òÒ»×éÔÚ¶ÁÈ¡Öмä»Ø¹öµÄÒ³Ãæ¡£ÓпÉÄÜ·¢ÉúÔà¶Á¡£½öÓ¦ÓÃÓÚ SELECT Óï¾ä¡£
PAGLOCK ÔÚͨ³£Ê¹Óõ¥¸ö±íËøµ ......
ÔÚsqlserver(Ó¦¸Ã˵ÔÚÄ¿Ç°ËùÓÐÊý¾Ý¿â²úÆ·)Öд´½¨Ò»¸ö×ÊÔ´Èç±í£¬ÊÓͼ£¬´æ´¢¹ý³ÌÖж¼ÒªÅжÏÓë´´½¨µÄ×ÊÔ´ÊÇ·ñÒѾ´æÔÚ
ÔÚsqlserverÖÐÒ»°ã¿Éͨ¹ý²éѯsys.objectsϵͳ±íÀ´µÃÖª½á¹û£¬²»¹ý¿ÉÒÔÓиü·½±ãµÄ·½·¨
ÈçÏ£º
if object_id('tb_table') is not null
......
sp_databases --Áгö·þÎñÆ÷ÉϵÄËùÓÐÊý¾Ý¿â
sp_server_info --Áгö·þÎñÆ÷ÐÅÏ¢£¬Èç×Ö·û¼¯£¬°æ±¾ºÍÅÅÁÐ˳Ðò
sp_stored_procedures--Áгöµ±Ç°»·¾³ÖеÄËùÓд洢¹ý³Ì
sp_tables --Áгöµ±Ç°»·¾³ÖÐËùÓпÉÒÔ²éѯµÄ¶ÔÏó
sp_start_job --Á¢¼´Æô¶¯×Ô¶¯»¯ÈÎÎñ
sp_stop_job --Í£Ö¹ÕýÔÚÖ´ÐеÄ×Ô¶¯»¯ÈÎÎñ
sp_password --Ìí¼Ó»òÐ ......
SQLServerÖеÄÑ»·Åú´¦Àí
GOÃüÁîºóÃæ¼ÓÒ»¸ö³£Á¿¾Í¿ÉÒÔÁË
ÏÂÃæ·½·¨¿ÉÒÔÓÃÀ´¿ìËÙÉú³ÉÒ»ÅúÊý¾Ý
if (object_id ('t' ) is not null ) drop table t
go
create table t (id int identity (1 , 1 ), name varchar (40 ))
go
insert into t (name ) select newid ()
go 10
select * from t
/*
1 &nbs ......