Précédent   Forum des professionnels en informatique > Bases de données > Sybase
Sybase Forum sur la base de données Sybase. Avant de poster -> F.A.Q Sybase, Tutoriels Sybase
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 28/07/2006, 12h09   #1
Membre habitué
 
Inscription : mars 2006
Messages : 293
Détails du profil
Informations forums :
Inscription : mars 2006
Messages : 293
Points : 140
Points : 140
Par défaut [T-SQL]convert champ binaire en char

Bonjour je reviens sur un sujet que j'avais ouvert il y'a qq jours, Michael Peppler m'avait aider pour résoudre une partie de mon problème, mais malgré tout je n'arrive pas a généré les noms des champs indexé pour un index donné.
Mon projet c'est de détruire les indexs des tables de mon appli et leurs récréation dans leurs états d'origine càd nom de champs, clusteriser ou non ect ... et ce de manière scripter (si qq'un a un script déja pret je suis preneur )
Mais malgré tout il me semble que ces noms sont stocké en binaire ds la table
syindexes sous key1 mais en binaire, et j'arrive pas a utiliser ce que m'avait dit Mickael l'utilisation de la fonction index_col()

En un mot HELP
Merci d'avance
arona est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/07/2006, 13h53   #2
Rédacteur/Modérateur
 
Inscription : janvier 2006
Messages : 1 301
Détails du profil
Informations personnelles :
Âge : 52

Informations forums :
Inscription : janvier 2006
Messages : 1 301
Points : 1 505
Points : 1 505
Envoyer un message via AIM à mpeppler
Voici un début. Attention, ce script ne gère pas les attributs des indexes (clustered, unique, max_rows_per_page, etc.), et n'a été que minimalement testé...

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
 
-- Un curseur sur tous les indexes des tables "user" dans la base courante:
declare ixcsr cursor
FOR SELECT name, id, indid FROM sysindexes
   WHERE id IN (SELECT id FROM sysobjects WHERE type = 'U')
go
 
SET nocount ON
 
declare @name varchar(32)
      , @id int
      , @indid int
      , @colid int
 
declare @cmd varchar(300)
      , @tab varchar(32)
      , @colname varchar(32)
      , @colorder varchar(32)
 
open ixcsr
 
fetch ixcsr INTO @name, @id, @indid
 
while @@sqlstatus = 0
begin
    SELECT @tab = object_name(@id)
 
    -- la commande de drop... celle-ci est triviale!
    SELECT @cmd = "drop index " + @tab + "." + @name
    print "%1!", @cmd
 
 
    -- on construit la commande de creation de facon iterative
    SELECT @colid = 1
 
    SELECT @cmd = "create index " + @name + " on " + @tab + "("
    while @colid <= 31
    begin
        SELECT @colname = index_col(@tab, @indid, @colid)
             , @colorder = index_colorder(@tab, @indid, @colid)
 
        -- si le nom est null c'est qu'on a traite toutes les colonnes de
        -- l'indexe
        IF @colname IS NULL
            goto LAST_COLUMN
 
        IF @colid > 1
            SELECT @cmd = @cmd + ", "
 
        SELECT @cmd =  @cmd + @colname + " " + @colorder
 
        SELECT @colid = @colid + 1
    end
 
    LAST_COLUMN:
    SELECT @cmd = @cmd + ")"
 
    print "%1!", @cmd
 
    fetch ixcsr INTO @name, @id, @indid
end
 
close ixcsr
 
deallocate cursor ixcsr
go

Michael
__________________
Michael Peppler
Membre de TeamSybase - www.teamsybase.com

"A successful [software] tool is one that was used to do something undreamed of by its author." -- S. C. Johnson
mpeppler est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/07/2006, 14h04   #3
Membre habitué
 
Inscription : mars 2006
Messages : 293
Détails du profil
Informations forums :
Inscription : mars 2006
Messages : 293
Points : 140
Points : 140
Merci mickael, je test!!
arona est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/07/2006, 17h37   #4
Rédacteur/Modérateur
 
Avatar de fadace
 
Homme Fabien Celaia
Administrateur de base de données
Inscription : octobre 2002
Messages : 3 779
Détails du profil
Informations personnelles :
Nom : Homme Fabien Celaia
Âge : 41
Localisation : Suisse

Informations professionnelles :
Activité : Administrateur de base de données
Secteur : Service public

Informations forums :
Inscription : octobre 2002
Messages : 3 779
Points : 8 124
Points : 8 124
Envoyer un message via ICQ à fadace Envoyer un message via Skype™ à fadace
Je me suis permis de l'ajouter aux sources Sybase
__________________
Sr DBA Oracle / Sybase / MS-SQL / DB2 / Informix / Postgresql
Administrateur SAP
Mes articles

Attention : pas de réponse technique par MP : pensez aux autres, passez par les forums !
fadace est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 31/07/2006, 11h59   #5
Rédacteur/Modérateur
 
Inscription : janvier 2006
Messages : 1 301
Détails du profil
Informations personnelles :
Âge : 52

Informations forums :
Inscription : janvier 2006
Messages : 1 301
Points : 1 505
Points : 1 505
Envoyer un message via AIM à mpeppler
Merci - il faudrait peut-être mettre un avertissement que le code ne fait pas une génération complète des commandes CREATE INDEX...

Michael
__________________
Michael Peppler
Membre de TeamSybase - www.teamsybase.com

"A successful [software] tool is one that was used to do something undreamed of by its author." -- S. C. Johnson
mpeppler est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 31/07/2006, 12h57   #6
Membre habitué
 
Inscription : mars 2006
Messages : 293
Détails du profil
Informations forums :
Inscription : mars 2006
Messages : 293
Points : 140
Points : 140
J'ai un autre petit script (fonction...) pour la génération des indexs, vous pouvez le tester au cas ou ...
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
 
fn_ExportDatabaseIndexes ()
{
isql -U${USER} -P${PASSWD} -S${toto_server} -D${KBC_MXDATABASE} -w2000
-o${EXPORT_INDEXES_FILE} << ENDSQL | tee -a ${EXPORT_LOG_FILE}
setuser "TITI_DB"
go
 
SET nocount ON
go
 
declare @ObjectId int
declare @LastObjectId int
declare @ObjectName varchar(50)
declare @IndId int
declare @LastIndId int
declare @IndName varchar(50)
declare @FieldId int
declare @FieldName varchar(50)
declare @KeysFields varchar(255)
declare @IndexDesc varchar(255)
 
SET nocount ON
 
setuser "MUREXDB"
 
SELECT @ObjectId = min (id)
FROM sysobjects
WHERE type='U'
 
IF @ObjectId IS NULL
begin
print "End of Process"
end
 
SELECT @ObjectName = object_name (@ObjectId)
 
while @ObjectId IS NOT NULL
begin
SELECT @IndId = min (indid)
FROM sysindexes
WHERE id = @ObjectId
AND indid > 0
AND indid < 255
 
while @IndId IS NOT NULL
begin
SELECT @FieldId = 1, @KeysFields = NULL,
@FieldName = "A"
while (@FieldId <= 31 AND @FieldName IS NOT NULL)
begin
SELECT @FieldName = index_col
(@ObjectName,@IndId,@FieldId)
IF @FieldName IS NOT NULL
begin
IF (@KeysFields IS NULL)
begin
SELECT
@KeysFields = @FieldName
end
else
begin
SELECT
@KeysFields = @KeysFields + "," + @FieldName
end
SELECT @FieldId = @FieldId
+ 1
end
end
 
SELECT @IndexDesc = ""
IF @IndId = 1
begin
SELECT @IndexDesc = "clustered "
end
IF @IndId > 1
begin
IF EXISTS (SELECT * FROM sysindexes
WHERE status2
& 512 = 512
AND indid =
@IndId
AND id =
@ObjectId)
begin
SELECT @IndexDesc =
"clustered "
end
else
begin
SELECT @IndexDesc =
"nonclustered "
end
end
 
IF EXISTS (SELECT * FROM master..spt_values V,
sysindexes I
WHERE I.STATUS
& V.number = V.number
AND V.type = "I"
AND V.number = 2
AND indid = @IndId
AND id =
@ObjectId)
begin
SELECT @IndexDesc = @IndexDesc +
V.name + " "
FROM master..spt_values V, sysindexes
I
WHERE I.STATUS & V.number
= V.number
AND V.type = "I"
AND V.number = 2
AND indid = @IndId
AND id = @ObjectId
end
 
SELECT @IndName = name FROM sysindexes
WHERE indid=@IndId
AND id=@ObjectId
 
print
"%1!;%2!;(%3!);%4!;-1",@ObjectName,@IndName,@KeysFields,@IndexDesc
 
SELECT @LastIndId = @IndId
SELECT @IndId = NULL
SELECT @IndId = min (indid)
FROM sysindexes
WHERE id = @ObjectId
AND indid > @LastIndId
AND indid < 255
end
SELECT @LastObjectId = @ObjectId
SELECT @ObjectId = NULL
SELECT @ObjectId = min (id)
FROM sysobjects
WHERE type='U'
AND id > @LastObjectId
 
SELECT @ObjectName = object_name (@ObjectId)
end
go
 
ENDSQL
}
arona est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 12h18.


 
 
 
 
Partenaires

Hébergement Web