Programmer列約束與表約束(SQL 語句)

2021-04-09 06:12:05 字數 1844 閱讀 5311

表結構的建立與修改(

sql

語句)一

:表結構定義語法格式

create table (

<

列名> <

列型別>[<

列屬性>][<

列約束>],

……,

[ <

表約束> ] )

[ on]

[ textimage_on ]

<

列型別>

就是sql server

支援的型別及相應的寬度.

<

列屬性> 列屬性中可以是如下幾種屬性:

(1)

預設值default 常量表示式.

(2)

標識identity (標識種子,標識遞增量)

<

列約束>

:: = [ constraintconstraint_name ]

[ clustered | nonclustered ]

[ withfillfactor = filltor ]

[ on ] ]

--------------------------------------

外來鍵約束

--------------------------------- |

[ [ foreign key]

referencesref_table [ (ref_column) ]

[ ondelete ]

[ onupdate] ]

[ notforreplication ] }

-------------------------------------- check

約束--------------------------------- |

check [ not for replication ] ( logical_expression )

<

表約束

> :

:= [ constraint constraint_name ]

[ clustered | nonclustered ]

[ with fillfactor = fillfactor ]

[ on ]

]

--------------------------------------

外來鍵約束

--------------------------------- |

foreign key

[ ( column [ ,...n ] ) ]

references ref_table [ ( ref_column [ ,...n ] ) ]

[ on delete ]

[ on update ]

[ not for replication ]

-------------------------------------- check

約束--------------------------------- |

check [ not for replication ] ( search_conditions )

}

二: 在定義primary key 的時候,我們可以有兩種方式出現:

列約束,

它只能給一列定義為主鍵,如果主鍵是多列的情況在此不適用。

表約束:

主鍵列可以是一列,或者是多列.

三: 學習:

1.

需要指定寬度的型別有:

char,varchar,nchar,nvarchar,binary,varbinary,

其它的型別均不

需要指定寬度,如果指定了寬度反而會出錯.

SQL unique約束之 表約束 與 列約束

唯一約束 unique 列約束 每個欄位都不能出現重複的資料 drop table ifexists studentinfo create table studentinfo studentid bigint unique 表約束 name varchar 255 unique 表約束 建表成功 新...

mysql 列約束 MySQL 列級約束和表級約束

一,六大約束 not null 非空 primary key 主鍵 unique 唯一 check 檢查約束,mysql 不支援,語法不報錯但無效果 foreign key 外來鍵.限制兩表關係,通常在從表引入外來鍵約束,引入主表中某列的值,保證從表該欄位的值必須 於主表關聯列的值 default預...

MySQL中的約束,列級約束,表級約束

總結了一些課上的筆記和 可以執行看看 約束的作用 一種限制,用於限制表中的資料,為了保證表中的資料的準確和可靠性。約束的分類 1.not null 非空,用於保證該欄位的值不能為null 2.default 預設值,用於保證該欄位在不設定具體的內容時,有一個預設值。即開始存資料的時候不不傳也會有一個...

Oracle 建表 約束 修改列

增加列 alter table name add columnname type 或者alter table name add columnname type 修改列名 alter table name rename column name1 to name2 刪除列alter table name...

Oralce建表 約束 修改列

增加列 alter table name add columnname type 修改列名 alter table name rename column name1 to name2 刪除列alter table name drop column name 將列設定不可用 alter table n...