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

sql code

--½áºÏsys.indexesºÍsys.index_columns,sys.objects,sys.columns²éѯË÷ÒýËùÊôµÄ±í»òÊÓͼµÄÐÅÏ¢
select
  o.name as ±íÃû,
  i.name as Ë÷ÒýÃû,
  c.name as ÁÐÃû,
  i.type_desc as ÀàÐÍÃèÊö,
  is_primary_key as Ö÷¼üÔ¼Êø,
  is_unique_constraint as ΨһԼÊø,
  is_disabled as ½ûÓÃ
from
  sys.objects o
inner join
  sys.indexes i
on
  i.object_id=o.object_id
inner join
  sys.index_columns ic
on
  ic.index_id=i.index_id and ic.object_id=i.object_id
inner join
  sys.columns c
on
  ic.column_id=c.column_id and ic.object_id=c.object_id
go
--²éѯË÷ÒýµÄ¼üºÍÁÐÐÅÏ¢
select
  o.name as ±íÃû,
  i.name as Ë÷ÒýÃû,
  c.name as ×ֶαàºÅ,
from
  sysindexes i inner join sysobjects o
on
  i.id=o.id
inner join
  sysindexkeys k
on
  o.id=k.id and i.indid=k.indid
inner join
  syscolumns c
on
  c.id=i.id and k.colid=c.colid
where
  o.name='±íÃû'
--²éѯÊý¾Ý¿âdbÖбítbµÄËùÓÐË÷ÒýµÄËæƬÇé¿ö
use db
go
select
  a.index_id,---Ë÷Òý±àºÅ
  b.name,---Ë÷ÒýÃû³Æ
  avg_fragmentation_in_percent---Ë÷ÒýµÄÂß¼­ËéƬ
from
  sys.dm_db_indx_physical_stats(db_id(),object_id(N'create.consume'),null,null,null) as a
join
  sys.indexes as b
on
  a.object_id=b.object_id
and
  a.index_id=b.index_id
go
---½âÊÍÏÂsys.dm_db_indx_physical_statsµÄ²ÎÊý
datebase_id: Êý¾Ý¿â±àºÅ£¬¿ÉÒÔʹÓÃdb_id()º¯Êý»ñÈ¡Ö¸¶¨Êý¾Ý¿âÃû¶ÔÓ¦µÄ±àºÅ¡£
object_id: ¸ÃË÷ÒýËùÊô±í»òÊÔͼµÄ±àºÅ
index_id: ¸ÃË÷ÒýµÄ±àºÅ
partition_number:¶ÔÏóÖзÖÇøµÄ±àºÅ
mode:ģʽÃû³Æ,ÓÃÓÚÖ¸¶¨»ñȡͳ¼ÆÐÅÏ¢µÄɨÃ輶±ð¡£
ÓйØsys.dm_db_indx_physical_statsµÄ½á¹û¼¯ÖеÄ×Ö¶ÎÃûÈ¥²éÏÂÁª»ú´ÔÊé¡£
---Ë÷ÒýÊÓͼ
Ë÷ÒýÊÓͼÊǾßÌ廯µÄÊÓͼ
--´´½¨Ë÷ÒýÊÓͼ
create view ÊÓͼÃû with schemabinding
as
select Óï¾ä
go
---´´½¨Ë÷ÒýÊÓͼÐèҪעÒâµÄ¼¸µã
1. ´´½¨Ë÷ÒýÊÓͼµÄʱºòÐèÒªÖ¸¶¨±íËùÊôµÄ¼Ü¹¹
--´íÎóд·¨
create view v_f with schemabinding
as
select
   a.a,a.b,b.a,b.b
from
 &nbs


Ïà¹ØÎĵµ£º

sql ¸ø±íÌí¼ÓÃèÊö

¼ÓÉϱíÃûºÍ±íÃèÊöºóÖ´ÐÐÒÔÏ´洢¹ý³Ì£¬¼´¿ÉΪ±íÌí¼ÓÃèÊö
EXEC

sys.sp_addextendedproperty @name=
N'MS_Description'
,

@value=
N'±íÃèÊö
'
,
@level0type=
N'SCHEMA'
,

@level0name=
N'dbo'
,

@level1type=
N'TABLE'
,

@level1name=
N'±íÃû'
......

50¸ö³£ÓÃsqlÓï¾ä

50¸ö³£ÓÃsqlÓï¾ä
Student(S#,Sname,Sage,Ssex) ѧÉú±í
Course(C#,Cname,T#) ¿Î³Ì±í
SC(S#,C#,score) ³É¼¨±í
Teacher(T#,Tname) ½Ìʦ±í
ÎÊÌ⣺
1¡¢²éѯ“001”¿Î³Ì±È“002”¿Î³Ì³É¼¨¸ßµÄËùÓÐѧÉúµÄѧºÅ;
  select a.S# from (select s#,score from SC where C#='001') a,(select s#,sc ......

SQLµÄ¼¸¸ö±àÂë¹æ·¶


1.±ÜÃâÔÚwhere×Ó¾äÖжÔ×Ö¶ÎÊ©¼Óº¯Êý£¬ÕâÑù½«µ¼ÖÂË÷ÒýʧЧ£¬±ÈÈ磺
select * from user where
to_char(create_time,'yyyymmdd')='20090101';
Ô­Òò£ºÔÚ½¨Á¢indexµÄʱºòÊǸù¾Ý×Ö¶ÎÀ´½¨Á¢µÄ£¬Ò²¾ÍÊÇ˵oracleÔÚinidexµÄʱºòÊÇË÷ÒýµÄ×ֶεÄÖµ£¬Èç¹ûÌṩ¸øoracleµÄÊÇÒ»¸öÐèÒª¾­¹ýº¯Êý´¦ÀíµÄ±È½Ï£¬oracle¾Íû°ì·¨Í¨¹ýË÷ÒýÖÐµÄ ......

sqlÌØÊâÓï·¨

¸´ÖƱíµÄ½á¹¹
select * into newtable from oldtable where 1<>1
¸´ÖƱí´ï¶îÄÚÈÝ
insert into new table select *(ÁÐÃû) from oldtable
datediffº¯ÊýÓ÷¨
×÷Óà    
  ·µ»ØÁ½¸öÈÕÆÚÖ®¼äµÄ¼ä¸ô¡£  
   
    Óï·¨   ......

SQL Server 2005&2008±¸·Ý»Ö¸´×ܽá

 
Ò»¡¢Êý¾Ý¿â´æ´¢¸ÅÊö
1¡¢Êý¾ÝÎļþÀàÐÍ
·         Primary data files:ÿ¸öÊý¾Ý¿â¶¼ÓÐÒ»¸öµ¥¶ÀµÄÖ÷ÒªÊý¾ÝÎļþ£¬Ä¬ÈÏÒÔ.mdfÀ©Õ¹Ãû¡£Ö÷ÒªÊý¾ÝÎļþ²»½ö°üº¬Êý¾ÝÐÅÏ¢£¬»¹°üº¬Óë¸ÃÊý¾Ý¿â½á¹¹Ïà¹ØµÄÐÅÏ¢¡£´´½¨Êý¾Ý¿âʱ£¬Êý¾Ý¿â½á¹¹Ïà¹ØÐÅÏ¢²»½ö´æÔÚÓÚmasterÊý¾Ý¿âÖУ¬Í¬Ê ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ