• mariaDB > modifier une table avec alter table

      AJOUTER UNE COLONNE

      alter table nom_table add nom_nouvelle_colonne col_definition [first|after nom_col]

       

      alter table customers add email varchar(255) not null;

      Plusieurs colonnes

      alter table table_name
          add new_col_nom col_definition [first | after nom_col],
          add new_col_nom col_definition [first | after nom_col],
          ...;

       

      alter table customers add phone varchar(15), add address varchar(255);

      MODIFIER UNE COLONNE

      alter table table_name modify col_name column_definition [first | after col_name];

       

      alter table customers modify phone varchar(20) not null;

      Plusieurs colonnes

      alter table table_name
          modify col_name col_definition [first | after col_name],
          modify col_name col_definition [first | after col_name],
          ...;

       

      alter table customers modify email varchar(255), modify address varchar(255) after name;

      Renommer une colonne

      alter table nom_table change column ancien_nom nouv_nom col_definition [first | after col_name];

       

      alter table customers change column address office_address varchar(255) not null;

      SUPPRIMER UNE COLONNE

      alter table table_name drop column nom_col;

       

      alter table customers drop column office_address;

      RENOMMER UNE TABLE

      alter table nom_table rename to nouveau_nom;

       

      alter table customers rename to clients;

       

 

Aucun commentaire

 

Laissez un commentaire