給乙個表增加列,重命表名

2021-06-26 21:10:40 字數 1376 閱讀 2062

如何在表中增加新的列alter tabel table_name add column_name,dateype(length)

alter table tablename1

add | alter [column] fieldname1

fieldtype [(nfieldwidth [, nprecision])]

[null | not null]

[check lexpression1 [error cmessagetext1]]

[default eexpression1]

[primary key | unique]

[references tablename2 [tag tagname1]]

[nocptrans] 

比如為table roaming_transfer_detail增加四列:total_ms,total_ms_error,total_me和 total_me_error。

alter table roaming_transfer_detail add (

total_ms number(10) null,

total_ms_error number(10) null,

total_me number(10) null,

total_me_error number(10) null

);

如果給乙個表明重新起名字:比如給表unit_credit_profile 重新命名為unit_credit_profiles。

alter table unit_credit_profile rename to unit_credit_profiles;

alter table scott.test rename to test1--修改表名

alter table scott.test rename column name to name1 --修改表列名

alter table scott.test modify name1 number(20) --修改字段型別

alter table scott.test add address varchar2(40) --新增表列

alter table scott.test drop name cascadeconstraints --刪除表列

當增加乙個列不為空值的時候:

alter table table_name add(column_name char(120) default '預設值')

乙個表中的兩列與另乙個表的一列關聯的結果顯示

station表 列名 stationid 站點編號 stationlon 站點經度 stationlat 站點緯度 record表 列名 recorkid 記錄編號 stationgoid 借出站點編號 stationbackid 歸還站點編號 查詢結果顯示列 stationgoid 借出站點編號...

乙個表中的兩列與另乙個表的一列關聯的結果顯示

station表 列名 stationid 站點編號 stationlon 站點經度 stationlat 站點緯度 record表 列名 recorkid 記錄編號 stationgoid 借出站點編號 stationbackid 歸還站點編號 查詢結果顯示列 stationgoid 借出站點編號...

用SQL語句給乙個表的增加自增主鍵或刪除主鍵

剛開始時碰到這個需求時,在網上搜尋了一下,發現都說不行,得先刪除那主鍵列再重新增加或者先建立乙個臨時表再把資料導過來,其實在mysql中是可以直接修改的。修改id欄位為自增主鍵 alter table test change id id int 11 unsigned not null auto i...