MySQL-DDL(データ定義言語)

1840 ワード

文書ディレクトリ
  • DDLデータ定義言語
  • ライブラリの管理
  • 作成
  • 修正
  • 削除
  • 表の管理
  • テーブルの作成
  • テーブル構造を表示
  • 表の修正
  • 列名を変更
  • 列のタイプまたは制約を変更する
  • 新しい列を追加
  • 削除列
  • 表名
  • を変更
  • 表の削除
  • テーブルのレプリケーション
  • DDLデータ定義言語
    ライブラリの管理
    作成
    create database 【if not exists】  ;
    

    変更
    今はもういらない
    rename database    to    ;
    

    ライブラリの文字セットの変更
    alter datebase    character set gbk;
    

    削除
    drop database if exists   ;
    

    テーブルの管理
    テーブルの作成
    create table   (
    	        【(  )   】,
    	        【(  )   】,
    	        【(  )   】,
    	...
    	        【(  )   】
    );
    

    テーブル構造の表示
    方式一
    desc   ;
    

    方式2
    show columns from   ;
    

    方程式3
    show create table   ;
    

    方式四
    show full fields from   ;
    

    テーブルの変更
    alter table    add|drop|modify|change column    【      】;
    

    列名の変更
    alter table    change column          
    

    列のタイプまたは制約の変更
    alter table    modify column      ;
    

    新しい列の追加
    alter table    add column      ;
    

    列の削除
    alter table    drop column   ;
    

    テーブル名の変更
    alter table    rename to    ;
    

    テーブルの削除
    drop table if exists   ;
    show tables;
    

    テーブルのコピー
    テーブルの構造のみをコピー
    create table       like   ;
    

    テーブルの構造+データのコピー
    create table      
    select * from   ;
    

    データの一部のみコピー
    create table      
    select   ,...
    from   
    where     ;
    

    一部のフィールドのみコピー
    create table      
    select   ,...
    from   
    where          ;