Précédent   Forum des professionnels en informatique > Bases de données > MS SQL-Server
MS SQL-Server Forum Microsoft SQL-Server. Avant de poster -> FAQ SQL-Server, Tutoriels SQL-Server
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 29/09/2008, 15h54   #1
Membre Expert
 
Inscription : octobre 2007
Messages : 3 948
Détails du profil
Informations forums :
Inscription : octobre 2007
Messages : 3 948
Points : 1 905
Points : 1 905
Par défaut SQL pour visualiser le schema d'une table

Bonjour

Je cherche la syntaxe SQL pour visualiser le schema d'une table en SQL Server

La liste des champs avec les types ?

Merci de votre aide
olibara est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/09/2008, 16h03   #2
Expert Confirmé
 
Avatar de rudib
 
Inscription : mai 2006
Messages : 2 236
Détails du profil
Informations personnelles :
Localisation : France, Paris (Île de France)

Informations forums :
Inscription : mai 2006
Messages : 2 236
Points : 2 983
Points : 2 983
Envoyer un message via ICQ à rudib Envoyer un message via MSN à rudib
Bonjour,

sp_help
ou la vue INFORMATION_SCHEMA.COLUMNS
__________________
Rudi Bruchez
Consultant indépendant
modélisation, administration, optimisation, formation,
solutions MS SQL Server et informatique libre.
MCDBA, MCITP, MCT, SCJP2 - http://www.babaluga.com/
Articles et tutoriels : http://rudi.developpez.com/
LIVRE : Optimiser SQL Server
rudib est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/09/2008, 16h24   #3
Membre Expert
 
Inscription : octobre 2007
Messages : 3 948
Détails du profil
Informations forums :
Inscription : octobre 2007
Messages : 3 948
Points : 1 905
Points : 1 905
Merci Rudy

C'est curieux que ces syntaxe soient toujours si esotériques

A quand une syntaxe SQL standard du style

select Table.schema from mytable

ou

select TableList from madatabase


olibara est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/09/2008, 16h27   #4
Membre chevronné
 
Avatar de cavo789
 
Homme Christophe Avonture
Développeur Web
Inscription : mai 2004
Messages : 649
Détails du profil
Informations personnelles :
Nom : Homme Christophe Avonture
Âge : 37
Localisation : Belgique

Informations professionnelles :
Activité : Développeur Web

Informations forums :
Inscription : mai 2004
Messages : 649
Points : 774
Points : 774
sp_help. Wow ! Superbe.

Pour info, il est possible d'analyser le code source de la procédure en allant dans la db master.

Ci-dessus un copy/paste du code trouvé. Il suffit d'adapter le nom de ta table.

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
declare @objid int
declare @sysobj_type char(2)
declare @numtypes nvarchar(80)
        select @numtypes = N'tinyint,smallint,decimal,int,real,money,float,numeric,smallmoney'

select @objid = object_id, @sysobj_type = type from sys.all_objects where object_id = object_id('NomDeLaTable')

select
            'Column_name'            = name,
            'Type'                    = type_name(user_type_id),
            'Computed'                = case when ColumnProperty(object_id, name, 'IsComputed') = 0 then 'No' else 'Yes' end,
            'Length'                    = convert(int, max_length),
            'Prec'                    = case when charindex(type_name(system_type_id), @numtypes) > 0
                                        then convert(char(5),ColumnProperty(object_id, name, 'precision'))
                                        else '     ' end,
            'Scale'                    = case when charindex(type_name(system_type_id), @numtypes) > 0
                                        then convert(char(5),OdbcScale(system_type_id,scale))
                                        else '     ' end,
            'Nullable'                = case when is_nullable = 0 then 'No' else 'Yes' end,
            'TrimTrailingBlanks'    = case ColumnProperty(object_id, name, 'UsesAnsiTrim')
                                        when 1 then 'No'
                                        when 0 then 'Yes'
                                        else '(n/a)' end,
            'FixedLenNullInSource'    = case
                        when type_name(system_type_id) not in ('varbinary','varchar','binary','char')
                            then '(n/a)'
                        when is_nullable = 0 then 'No' else 'yes' end,
            'Collation'        = collation_name
        from sys.all_columns where object_id = @objid
__________________
Christophe
Développeur de l'extension AllEvents, gestionnaire d'évènements pour Joomla
http://avonture.be/allevents - https://www.facebook.com/com.allevents - http://twitter.com/#!/avonture
cavo789 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/09/2008, 16h36   #5
Expert Confirmé
 
Avatar de rudib
 
Inscription : mai 2006
Messages : 2 236
Détails du profil
Informations personnelles :
Localisation : France, Paris (Île de France)

Informations forums :
Inscription : mai 2006
Messages : 2 236
Points : 2 983
Points : 2 983
Envoyer un message via ICQ à rudib Envoyer un message via MSN à rudib
pour utiliser sp_help en un clin d'oeil : sélectionner le nom d'une table dans Query Analyzer / SSMS (dans la fenêtre de code), et faire ALT+F1
__________________
Rudi Bruchez
Consultant indépendant
modélisation, administration, optimisation, formation,
solutions MS SQL Server et informatique libre.
MCDBA, MCITP, MCT, SCJP2 - http://www.babaluga.com/
Articles et tutoriels : http://rudi.developpez.com/
LIVRE : Optimiser SQL Server
rudib est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/09/2008, 17h55   #6
Rédacteur/Modérateur

 
Avatar de SQLpro
 
Homme Frédéric BROUARD
Expert SGBDR & SQL
Inscription : mai 2002
Messages : 10 959
Détails du profil
Informations personnelles :
Nom : Homme Frédéric BROUARD
Localisation : France

Informations professionnelles :
Activité : Expert SGBDR & SQL
Secteur : Conseil

Informations forums :
Inscription : mai 2002
Messages : 10 959
Points : 17 792
Points : 17 792
INFORMATION_SCHEMA.COLUMNS est la norme SQL !

A lire : http://sqlpro.developpez.com/cours/s...age=partie2#L9

A +
__________________
Frédéric Brouard - SQLpro - ARCHITECTE DE DONNÉES - expert SGBDR et langage SQL
Site sur les SGBD relationnels et le langage SQL: http://sqlpro.developpez.com/
Expert Microsoft SQL Server - M.V.P. (Most valuable Professional) MS Corp.
Blog SQL, SQL Server, modélisation données : http://blog.developpez.com/sqlpro
http://www.sqlspot.com : modélisation, conseils, audit, optimisation, formation
* * * * * Enseignant CNAM PACA - ISEN Toulon - CESI Aix en Provence * * * * *
SQLpro est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/09/2008, 19h45   #7
Membre Expert
 
Inscription : octobre 2007
Messages : 3 948
Détails du profil
Informations forums :
Inscription : octobre 2007
Messages : 3 948
Points : 1 905
Points : 1 905
Merci a tous !

Me voila plus malin !
olibara est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 06h48.


 
 
 
 
Partenaires

Hébergement Web