日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
不允許設(shè)置db2主鍵問題的解決

設(shè)置db2主鍵問題出錯(cuò)的話,應(yīng)該如何處理呢?下面就教您一個(gè)不允許設(shè)置db2主鍵問題的解決方法,希望對(duì)您學(xué)習(xí)設(shè)置db2主鍵方面有所幫助。

創(chuàng)新互聯(lián)建站專注于津南網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供津南營銷型網(wǎng)站建設(shè),津南網(wǎng)站制作、津南網(wǎng)頁設(shè)計(jì)、津南網(wǎng)站官網(wǎng)定制、成都微信小程序服務(wù),打造津南網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供津南網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

將empno設(shè)置為主鍵

db2 => alter table emp add primary key (empno)

DB21034E The command was processed as an SQL statement because it was not a

valid Command Line Processor command. During SQL processing it returned:

SQL0542N "EMPNO" cannot be a column of a primary key or unique key because it

can contain null values. SQLSTATE=42831

fenced  出現(xiàn)問題的原因是,因?yàn)閑mpno列在創(chuàng)建的時(shí)候,默認(rèn)支持值為空。而在DB2中,針對(duì)這種情況,是不允許創(chuàng)建主鍵的。這點(diǎn)也與oracle和mysql不同。

fenced  因此,我們要添加主鍵,需要先修改empno,添加上約束,讓此列為非空:

db2 => alter table emp alter column empno set not null

將列修改了之后,嘗試添加主鍵,再次出錯(cuò):

db2 => alter table emp add primary key (empno)

DB21034E The command was processed as an SQL statement because it was not a

valid Command Line Processor command. During SQL processing it returned:

SQL0668N Operation not allowed for reason code "7" on table "DB2INST1.EMP".

SQLSTATE=57016

解決辦法:

查看錯(cuò)誤信息代碼SQL0668N,去查看具體的code“7”的含義。

db2 => ? SQL0668N

SQL0668N Operation not allowed for reason code "" on table

     "".

Explanation:

Access to table "" is restricted. The cause is based on the

following reason codes "":

1fenced

fenced  The table is in the Set Integrity Pending No Access state.

。。。。。內(nèi)容省略。。。。。。。。

7fencedThe table is in the reorg pending state. This can occur after

fenced  an ALTER TABLE statement containing a REORG-recommended

fenced  operation.

User response:

1fencedExecute the SET INTEGRITY statement with the IMMEDIATE CHECKED

fenced  option on table "" to bring the table out of the

。。。。。內(nèi)容省略。。。。。。。。

7fencedReorganize the table using the REORG TABLE command.

fenced  For a table in the reorg pending state, note that the following

fenced  clauses are not allowed when reorganizing the table:

fenced  

fenced  * The INPLACE REORG TABLE clause

fenced  * The ON DATA PARTITION clause for a partitioned table when

fenced     table has nonpartitioned indexes defined on the table

通過查看上述描述中的紅色部分的文字,emp表的empno列是添加了not null約束而導(dǎo)致表出于了“reorg pending state”這種狀態(tài)。我們可以通過以下的方法來驗(yàn)證:

db2 => load query table emp

Tablestate:

Reorg Pending

解決辦法,參照6.1中的“User response”描述,使用REORG TABLE命令:

db2 => reorg table emp

DB20000I The REORG command completed successfully.

修改完成后,再次添加主鍵:

db2 => alter table emp add primary key(empno)

DB20000I The SQL command completed successfully.

查看下表的狀態(tài),若為normal則能夠正常得進(jìn)行操作:

db2 => load query table emp

Tablestate:

Normal

總結(jié):對(duì)表添加主鍵時(shí)出現(xiàn)的錯(cuò)誤,是由于之前對(duì)表的列進(jìn)行了修改,添加了非空約束,導(dǎo)致整個(gè)表出于“Reorg Pending”狀態(tài)。

針對(duì)表出現(xiàn)這種狀況時(shí),使用reorg table命令,將表進(jìn)行reorganize即可。
 

【編輯推薦】

DB2臨時(shí)表定義的方法

linux下安裝DB2的步驟

DB2性能優(yōu)化的十大注意事項(xiàng)

SQL SERVER連接DB2數(shù)據(jù)庫

DB2索引創(chuàng)建原則


網(wǎng)頁名稱:不允許設(shè)置db2主鍵問題的解決
網(wǎng)頁鏈接:http://m.5511xx.com/article/cdcddio.html