Dans la boite à outil SQL Server, deux fonctions pour, respectivement,
lister les tables et vue et leur colonnes
if
exists(select * from sysobjects
where name=N'TablesEtVues' and
type='IF')
drop function TablesEtVues
go
create
function
TablesEtVues() returns TABLE
as
RETURN(
select
o.name,
case o.type
when 'U'
then 'Table'
when 'V'
then 'Vue'
when 'IF'
then 'Fonction de
sélection'
end as 'type',
o.id
from sysobjects o where
o.type in ('U', 'V',
'IF') and
o.status>0
)
go
if
exists(select * from sysobjects
where name=N'ColonnesDeTable' and
type='IF')
drop function ColonnesDeTable
go
create
function
ColonnesDeTable(@TableName varchar(50))
returns TABLE
as
RETURN(
select c.colid colid, c.name colname, t.name typename,
c.length length, c.xprec prec, c.xscale scale
from syscolumns c
inner join sysobjects o on c.id = o.id
left join systypes t on
t.xtype=c.xtype and
t.usertype=c.usertype
where o.type in
('S', 'U', 'V',
'IF') and
o.name=@TableName
)
go