1、查詢資料庫中的表,其中,xtype為u是資料庫表,是p為儲存過程,v為檢視等。
select * from sysobjects where xtype='u' and name like 'task%' order by name;
2、查詢資料表的列
select a.name,b.name
from sysobjects a
left outer join syscolumns b on a.id=b.id
where a.xtype='u' and a.name = 'taskline'
3、查詢表結構資訊
select (case when a.colorder=1 then d.name else null end) 表名,
a.colorder 字段序號,a.name 欄位名,
(case when columnproperty( a.id,a.name,'isidentity')=1 then '√'else '' end) 標識,
(case when (select count(*) from sysobjects
where (name in (select name from sysindexes
where (id = a.id) and (indid in
(select indid from sysindexkeys
where (id = a.id) and (colid in
(select colid from syscolumns where (id = a.id) and (name = a.name)))))))
and (xtype = 'pk'))>0 then '√' else '' end) 主鍵,b.name 型別,a.length 占用位元組數,
columnproperty(a.id,a.name,'precision') as 長度,
isnull(columnproperty(a.id,a.name,'scale'),0) as 小數字數,(case when a.isnullable=1 then '√'else '' end) 允許空,
isnull(e.text,'') 預設值,isnull(g.[value], ' ') as [說明]
from syscolumns a
left join systypes b on a.xtype=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 sys.extended_properties g on a.id=g.major_id and a.colid=g.minor_id
left join sys.extended_properties f on d.id=f.class and f.minor_id=0
where b.name is not null
--where d.name='要查詢的表' --如果只查詢指定表,加上此條件
order by a.id,a.colorder
4、查詢表的結構資訊
select a.name 表名,b.name 欄位名,c.name 字段型別,c.length 字段長度 from sysobjects a,syscolumns b,systypes c where a.id=b.id
and a.name='cly_uploadrecord' and a.xtype='u'
and b.xtype=c.xtype
資料庫的表查詢改刪
選擇資料庫 use mytest create tablemytest id int primary key auto increment unsigned engine innodb alter table student engine innodb 檢視資料庫當中有哪些表 檢視表結構 show ...
關聯表查詢資料庫
1.呼叫方法 this getrelationlist m map,bd prefix.deal as d left join db prefix.user as u on d.user id u.id d.u.site id d.id map指的是查詢條件陣列 2.實現函式 protected f...
mysql查詢資料庫表
使用sql語句查詢mysql指定表字段。可以方便整理資料庫表的說明文件。我在工作中整理了部分sql作為記錄。可以用在以後的mysql文件匯出工具裡。以下為具體內容 使用sql查詢指定資料庫表名和表說明。select table name as tablename,table comment as c...