將sqlserver中的表結構匯出

2022-05-06 11:12:13 字數 1054 閱讀 7868

寫文件時會遇到需要資料庫中表結構的時候  執行一下語句可以輕鬆匯出表結構

select

表名=case when a.colorder=1 then d.name 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 parent_obj=a.id 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,'')

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

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

order by a.id,a.colorder

如何將SqlServer中表結構以及表資料全部匯出

不記錄,很快就忘記了 記錄了,彷彿也記得更牢了 步驟如下 step1 右擊資料庫,彈出的標籤中選擇tasks generate scripts.step2 彈出新視窗中,勾選 請下次別煩了別通知我了 然後點選下一步 step3 在又彈出的新頁面,選擇指定的資料庫,然後勾選你想要的表,選擇完畢了,再選...

SQL Server讀取表結構到變數中

工作中,經常會遇到將某個資料表的所有或大部份字段讀取出來情況,比如說跨資料庫進行表更新或插入等。假如欄位名乙個乙個地敲的話,一是效率低,二是會有漏掉的情況。針對此種情況,處理的方法有很多種,比如新建乙個檢視,在裡面錄入select from 表名,系統會自動將星號改成欄位名 sql server 2...

SqlServer 獲取表結構

1.獲取表的基本字段屬性 獲取sqlserver中表結構 select syscolumns.name,systypes.name,syscolumns.isnullable,syscolumns.length from syscolumns,systypes where syscolumns.xu...