国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

命名約束 vs 系統生成的約束

2024-07-21 02:12:45
字體:
來源:轉載
供稿:網友

當你為一個表定義約束時,給約束命名是一個好習慣。另外,sql server會為約束創建系統自動生成的名稱。當在沒有給約束命名的情況下,生成數據定義語言(ddl)(當ddl應用在幾個數據庫上時),那么系統生產約束名一般是不一樣的。

 
在為數據庫生成計劃后,再生成詳細的約束列表,與一個詳細計劃構造的合法約束列表進行對比,是一個很好的習慣。當數據庫相當大時,這樣做是非常有益的。

下面的腳本演示了命名約束、不命名約束及系統自動生成的約束名之間的區別,三者使用了同樣的表,只不過每次都是重新創建的:

create table parent
(pkey1 int not null
       constraint pk_parent primary key (pkey1))
go


create table constraintname
(pkey int not null
 constraint pk_cnstnm primary key,
 parent_pkey1 int not null,
col1  int null
 constraint ck_cnstnm_col1 check  (col1 in ( 'a','b' ) )
 constraint df_cnstnm_col1 default 1,
constraint fk_parent_cnstnm foreign key (parent_pkey1)
       references parent (pkey1)
)
go
exec sp_helpconstraint constraintname
go
drop table constraintname
go
create table constraintname
(pkey int not null
       primary key,
 parent_pkey1 int not null
       foreign key (parent_pkey1) references parent(pkey1),
 col1  int null
       check  (col1 in ( 'a','b' ) )
       default 1
)
go
exec sp_helpconstraint constraintname
go
drop table constraintname
go
create table constraintname
(pkey int not null
       primary key,
 parent_pkey1 int not null
       foreign key (parent_pkey1) references parent(pkey1),
 col1  int null
       check  (col1 in ( 'a','b' ) )
       default 1
)
go
exec sp_helpconstraint constraintname
go
drop table constraintname
go
drop table parent
go

注冊會員,創建你的web開發資料庫,
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 华容县| 嘉义市| 巴马| 龙陵县| 阳春市| 安义县| 乌鲁木齐县| 德清县| 澳门| 秦皇岛市| 土默特左旗| 岳西县| 甘南县| 岳池县| 华坪县| 甘谷县| 鄂伦春自治旗| 桃源县| 肥东县| 河间市| 绍兴县| 陆良县| 金坛市| 黄骅市| 虹口区| 平乐县| 安顺市| 大港区| 多伦县| 巴林右旗| 大渡口区| 大石桥市| 济宁市| 临猗县| 海城市| 江安县| 东城区| 鄂尔多斯市| 武宣县| 古蔺县| 凤台县|