精彩SQL集錦(一)

2021-04-02 19:31:45 字數 1214 閱讀 4540

select

表名=case when a.colorder=1 then d.name else '' end,

表說明=case when a.colorder=1 then isnull(f.value,'') else '' end,

字段序號=a.colorder,

欄位名=a.name,

標識=case when columnproperty( a.id,a.name,'isidentity')=1 then '√'else '' end,

主鍵=case when exists(select 1 from sysobjects where xtype='pk' and name in (

select name from sysindexes where indid in(

select indid from sysindexkeys where id = a.id and colid=a.colid

))) then '√' else '' end,

型別=b.name,

占用位元組數=a.length,

長度=columnproperty(a.id,a.name,'precision'),

小數字數=isnull(columnproperty(a.id,a.name,'scale'),0),

允許空=case when a.isnullable=1 then '√'else '' end,

預設值=isnull(e.text,''),

字段說明=isnull(g.[value],'')

from syscolumns a

left join systypes b on a.xusertype=b.xusertype

inner join sysobjects d on a.id=d.id  and d.xtype='u' and  d.name<>'dtproperties'

left join syscomments e on a.cdefault=e.id

left join sysproperties g on a.id=g.id and a.colid=g.**allid 

left join sysproperties f on d.id=f.id and f.**allid=0

--where d.name='要查詢的表'    --如果只查詢指定表,加上此條件

order by a.id,a.colorder

SQL語句集錦

use tablename 要操作的資料庫名 select logicalfilename tablename log 日誌檔名 maxminutes 10,limit on time allowed to wrap log.newsize 1 你想設定的日誌檔案的大小 m setup initia...

初學SQL錯誤集錦

1 通過 sql,您如何從 persons 表中選取 firstname 列?答 select firstname from persons 2 通過 sql,您如何按字母順序選取 persons 表中 lastname 介於 adams 和 carter 的所有記錄?答 select from p...

常見sql語句集錦

1.unix timestamp 自 1970 01 01 00 00 00 的到當前時間的秒數差 2.select unix timestamp 2012 06 08 獲取date 日期的時間戳 3.select if unix timestamp 1000 createtime select t...