データベースのデータ制約

どのデータ制約:

        ユーザー操作テーブルのデータを制限します。

1.デフォルト値(デフォルトの制約)

効果:ユーザーがデフォルト値を使用するフィールドに値を挿入しない場合、デフォルト値が使用されます。

テーブル名を作成(
        フィールド名フィールドタイプデフォルトデフォルト値、
        フィールド名フィールドタイプ

2.空ではない    

役割:制限フィールドを割り当てる必要があります

テーブル名を作成(
        フィールド名フィールドタイプがnull はありません
        フィールド名フィールドタイプ
  

 

3.一意(空でない+一意)

テーブル名を作成(
        フィールド名、フィールドタイプ、主キー、
        フィールド名フィールドタイプ
        フィールド名フィールドタイプ       

 

4、自己成長(int型でなければならず、それが主キーです)

テーブル名を作成(
        フィールド名フィールドタイプ主キーauto_increment、
        フィールド名フィールドタイプ
        フィールド名フィールドタイプ       

 

 

5.外部キー

役割:2つのテーブルのデータを制限する

create table table name 1(
        field name 1 field type 1 primary key、
        field name 2 field type 2
)   


create table table name 2(
        field name 3 field type 3 primary key、
        field name 4 field type 4、
        field name 5 field type 5
       制約の外部キー名(fk_table 1_table 2など)外部キー(フィールド名5)がテーブル1(フィールド1)を                     
参照)

 

おすすめ

転載: www.cnblogs.com/heitaitou/p/12746403.html