IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Sybase Discussion :

[T-SQL]convert champ binaire en char


Sujet :

Sybase

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    293
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 293
    Points : 182
    Points
    182
    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

  2. #2
    Membre chevronné

    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    1 307
    Détails du profil
    Informations personnelles :
    Âge : 64
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2006
    Messages : 1 307
    Points : 1 828
    Points
    1 828
    Par défaut
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    293
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 293
    Points : 182
    Points
    182
    Par défaut
    Merci mickael, je test!!

  4. #4
    Rédacteur/Modérateur

    Avatar de Fabien Celaia
    Homme Profil pro
    Administrateur de base de données
    Inscrit en
    Octobre 2002
    Messages
    4 222
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : Suisse

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

    Informations forums :
    Inscription : Octobre 2002
    Messages : 4 222
    Points : 19 551
    Points
    19 551
    Billets dans le blog
    25
    Par défaut
    Je me suis permis de l'ajouter aux sources Sybase
    Sr DBA Oracle / MS-SQL / MySQL / Postgresql / SAP-Sybase / Informix / DB2

    N'oublie pas de consulter mes articles, mon blog, les cours et les FAQ SGBD

    Attention : pas de réponse technique par MP : pensez aux autres, passez par les forums !

  5. #5
    Membre chevronné

    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    1 307
    Détails du profil
    Informations personnelles :
    Âge : 64
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2006
    Messages : 1 307
    Points : 1 828
    Points
    1 828
    Par défaut
    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

  6. #6
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    293
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 293
    Points : 182
    Points
    182
    Par défaut
    J'ai un autre petit script (fonction...) pour la génération des indexs, vous pouvez le tester au cas ou ...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    }

Discussions similaires

  1. SQL Server 2003, champs binaires long
    Par ep31 dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 16/09/2008, 10h50
  2. Recherche dans un champs binaire
    Par roots_man dans le forum ASP
    Réponses: 3
    Dernier message: 29/08/2005, 08h30
  3. [SQL] Convertir un champ INT en CHAR dans un SELECT ?
    Par webtheque dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 17/03/2005, 14h45
  4. Pb sur une requête SQL (de champ vide)
    Par Marion dans le forum Langage SQL
    Réponses: 3
    Dernier message: 01/07/2004, 11h12
  5. [sql] [jointure] champs = substring(champs,1,5)
    Par DaxTaz dans le forum Langage SQL
    Réponses: 2
    Dernier message: 26/05/2004, 12h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo