DDL(データベース定義言語):
2213 ワード
DDL(データベース定義言語):
1、DDL(Data Definition Language)の文法:
1.1データベースの作成とテーブルの作成:
構文:
create database if not existsデータベース名;
create table if not existsテーブル名(
フィールド名フィールドタイプフィールド制約
)
1.1.1表フィールド命名規則:構成:英語の単語、数字、普通の記号 見名知意 大文字と小文字を区別せず、""区別、例えば:my_Name;
英字で始まる キーワード は使用できません.
1.1.2フィールド制約:
フィールドの整合性:
データ型、デフォルト:default、非空:not null
エンティティの整合性:
プライマリ・キー:primary key
自動成長じどうぞうか:increment increment
ユニークキー、インデックス
表の整合性:
外部キー:foreign key
構文:foreigm key外部キーテーブルフィールド名referencesプライマリキーテーブルのカラム名
カスタム整合性:
トランザクション、ビュー、関数、ストアド・プロシージャ
1.1.3フィールドの属性:数値 整数:int,bigint 小数:float,double,real,decimal 文字: char:可変文字で、長さが足りない場合は をスペースで埋めます. varchar:長さ可変 text:大きな を保存 blob:大フィールドデータ型 日付:date,datetime,time,timestamp,now() mysqlはブールをサポートしていないのでtinyint、1はtrue、0はfalse です.
1.2データベースの削除とテーブルの削除:
構文:
drop database if existsデータベース名;
drop table if existsテーブル名;
1.3 alter:
表名の変更:alter table旧表名rename[to]新表名;
フィールドの変更:alter tableテーブル名change[column]元のフィールド名新しいフィールド名データ型制約
alter tableテーブル名modify[column]フィールド名データ型制約
追加フィールド:alter tableテーブル名add[column]フィールド名データ型[属性];
削除フィールド:alter tableテーブル名dropフィールド名;
1.4基本操作:すべてのデータベース名を表示:show database; 選択データベース:uesデータベース名; 表示表:show tables; データベースを探す:show databases; 表の詳細:desc表名;
1、DDL(Data Definition Language)の文法:
1.1データベースの作成とテーブルの作成:
構文:
create database if not existsデータベース名;
create table if not existsテーブル名(
フィールド名フィールドタイプフィールド制約
)
# ,
create database if not exists text;
# if not exists text 。
create database text;
# if not exists ,
create table if not exists text(
text1 int(2) not null
)
1.1.1表フィールド命名規則:
1.1.2フィールド制約:
フィールドの整合性:
データ型、デフォルト:default、非空:not null
エンティティの整合性:
プライマリ・キー:primary key
自動成長じどうぞうか:increment increment
ユニークキー、インデックス
表の整合性:
外部キー:foreign key
構文:foreigm key外部キーテーブルフィールド名referencesプライマリキーテーブルのカラム名
カスタム整合性:
トランザクション、ビュー、関数、ストアド・プロシージャ
1.1.3フィールドの属性:
1.2データベースの削除とテーブルの削除:
構文:
drop database if existsデータベース名;
drop table if existsテーブル名;
# ,
drop database if exists text;
# if exists text 。
drop table if exists text;
1.3 alter:
表名の変更:alter table旧表名rename[to]新表名;
フィールドの変更:alter tableテーブル名change[column]元のフィールド名新しいフィールド名データ型制約
alter tableテーブル名modify[column]フィールド名データ型制約
追加フィールド:alter tableテーブル名add[column]フィールド名データ型[属性];
削除フィールド:alter tableテーブル名dropフィールド名;
# :alter table rename [to] ;
alter table s1 rename s2;
# :alter table change [column] ;
alter table s2 change name myname char not null;
# :alter table add [column] [ ];
alter table s2 add name varchar not null;
# :alter table drop ;
alter table s2 drop myname;
1.4基本操作: