2012-03-21 102 views
0

我創建的表沒有主鍵更新一列有主鍵

像這樣:

private static final String SCRIPT_CREATE_DATABASE = 
     "create table " + MYDATABASE_TABLE + " (" 
     + KEY_ID + " INT, " 
     + KEY_CONTENT1 + " , " 
     + KEY_CONTENT2 + " , " + KEY_CONTENT3 +" date, " + KEY_CONTENT4 + 
     " , " + KEY_CONTENT5 + 
     " , " + KEY_CONTENT6 + 
     " , " + KEY_CONTENT7 + 
     " , " + KEY_CONTENT8 + 
     " , " + KEY_CONTENT9 + 
     " , " + KEY_CONTENT10 + 
     " , " + KEY_CONTENT11 + 
     " , " + KEY_CONTENT12 + 
     " , " + KEY_CONTENT13 + 
    ");"; 

,但我想更新的行KEY_ID應該有主鍵,在表中有沒有主鍵創建,我可以更新表嗎?,請幫助。

回答

1

聲明列KEY_ID作爲主鍵

private static final String SCRIPT_CREATE_DATABASE = 
    "create table " + MYDATABASE_TABLE + " (" 
    + KEY_ID + "integer primary key, " 
    + KEY_CONTENT1 + " , " 
    + KEY_CONTENT2 + " , " + KEY_CONTENT3 +" date, " + KEY_CONTENT4 + 
    " , " + KEY_CONTENT5 + 
    " , " + KEY_CONTENT6 + 
    " , " + KEY_CONTENT7 + 
    " , " + KEY_CONTENT8 + 
    " , " + KEY_CONTENT9 + 
    " , " + KEY_CONTENT10 + 
    " , " + KEY_CONTENT11 + 
    " , " + KEY_CONTENT12 + 
    " , " + KEY_CONTENT13 + 
");"; 
+0

我創建的表並且它正在使用中....我想將列KEY_ID更新爲primatykey – user933909 2012-03-21 09:33:37

+1

你試過這個查詢:ALTER TABLE MYDATABASE_TABLE ADD PRIMARY KEY(KEY_ID) – sush 2012-03-21 09:38:02

+0

試試這個ALTER TABLE MYDATABASE_TABLE ADD KEY_ID主鍵 – Nishant 2012-03-21 09:50:22

0

如果妳只是想改變1列,並使其主要那就試試這個
ALTER TABLE MYDATABASE_TABLE ADD PRIMARY KEY(KEY_ID)