首页 > 其他分享 >如何为增加的列指定位置 (zz)

如何为增加的列指定位置 (zz)

时间:2023-06-09 18:08:27浏览次数:29  
标签:09 column 位置 col2 指定 zz SQL table TABLE


修改表的例子:

Examples


Add a column to a table
   ALTER TABLE STAFF_OPTIONS
      ADD SO_INSURANCE_PROVIDER Varchar2(35);

Add  a default value to a column
   ALTER TABLE STAFF_OPTIONS
      MODIFY SO_INSURANCE_PROVIDER Varchar2(35) DEFAULT 'ABC Ins';

Add two columns to a table and remove a constraint
   ALTER TABLE STAFF_OPTIONS
      ADD (SO_STAFF_ID INT, SO_PENSION_ID INT)
          STORAGE INITIAL 10 K
          NEXT 10 K
          MAXEXTENTS 121
          PCTINCREASE 0
          FREELISTS 2
      DROP CONSTRAINT cons_SO;


//z 2012-08-09 09:33:52 IS2120@.T1428351245[T63,L414,R16,V609] 

 How does one add a column to the middle of a table? 

 Submitted by admin on Sat, 2005-12-03 00:53 


 Oracle only allows columns to be added to the end of an existing table. Example: 


 SQL> CREATE TABLE tab1 ( col1 NUMBER ); 


 Table created. 


 //z 2012-08-09 09:33:52 IS2120@T1428351245[T63,L414,R16,V609] 

 SQL> ALTER TABLE tab1 ADD (col2 DATE); 


 Table altered. 


 SQL> DESC tab1 

  Name                                      Null?    Type 

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

  COL1                                               NUMBER 

  COL2                                               DATE 


 Nevertheless, some databases also allow columns to be added to an existing table after a particular column (i.e. in the middle of the table). For example, in MySQL the following syntax is valid: 


 ALTER TABLE tablename ADD columnname AFTER columnname; 


 Oracle does not support this syntax. However, it doesn't mean that it cannot be done. 


 Workarounds: 


 1. Create a new table and copy the data across. 


 SQL> RENAME tab1 TO tab1_old; 


 Table renamed. 


 SQL> CREATE TABLE tab1 AS SELECT 0 AS col1, col1 AS col2 FROM tab1_old; 


 Table created. 


 2. Use the DBMS_REDEFINITION package to change the structure on-line while users are workining. 

 ‹ Can one retrieve only the Nth row from a table? up How does one drop/ rename a columns in a table? › 

 » 


     Login to post comments 


 How does one add a column to the middle of a table? 

 Submitted by samar bijaya panda (not verified) on Tue, 2006-02-21 06:21. 


 Here is another workaround: 


 create table emptest as select empno, 1 as id, 'x' as emp_name, ename from emp; 


 In the code above, replace 1 as id, 'x' as emp_name with your new columns. 

 » 


     Login to post comments 


 How does one add a column to the middle of a table? 

 Submitted by Kalyani P. Banerjee (not verified) on Tue, 2006-07-25 00:14. 


 To add a column in middle of the table of varchar data type: 


 SQL>create table test (ename varchar2(20),salary number); 

 Table created 


 SQL>desc test; 

 Name Null? Type 

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

 ENAME VARCHAR2(20) SALARY NUMBER 


 [i]SQL>rename test to test1; 

 Table renamed 

 [ii]SQL>create table test2 (id varchar2(20)); 

 Table created 

 [iii]SQL>create table test as(select test1.ename,test2.id,test1.salary from test1,test2); 

 Table created 

 ........................................................................................ 

 SQL>desc test; 

 Name Null? Type 

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

 ENAME VARCHAR2(20) 

 ID VARCHAR2(20) 

 SALARY NUMBER 

 » 

 //z 2012-08-09 09:33:52 IS2120@1428351245[T63,L414,R16,V609] 

 How does one add a column to the middle of a table? 

 Submitted by SandhyaRR on Mon, 2010-09-27 03:09. 


 There is a table T with col1 and col2 and you want to add a new column col3 after col1. 


 1. Rename the column col2 to col3 as: 

 ALTER TABLE tablename RENAME COLUMN col2 TO col3; 


 2. Add a new column to the table 

 alter table t1 add (col2 datatype); 


 3.Now finally interchange the data contained in the two column: 

 UPDATE EMPLOYEE 

 SET col2 = col3 

 ,col3 = col2 


 Note: Data types of the interchanged columns should match. 

 //z 2012-08-09 09:33:52 IS2120@.T1428351245[T63,L414,R16,V609]

标签:09,column,位置,col2,指定,zz,SQL,table,TABLE
From: https://blog.51cto.com/u_16156420/6449627

相关文章

  • 任正非:一江春水向东流 (zz)
    小时候,妈妈给我们讲希腊大力神的故事,我们崇拜得不得了。少年不知事的时期我们崇拜上李元霸、宇文成都这种盖世英雄,传播着张飞“杀”(争斗)岳飞的荒诞故事。在青春萌动的时期,突然敏感到李清照的千古情人是力拔山兮的项羽。至此“生当作人杰,死亦为鬼雄”又成了我们的人生警句。当然这......
  • PieLove 之 数据分析帝.(ZZ)(is2120)
    //z2015-11-1813:11:20L.43'38920BG57IV3@XCLT3124966025.K.F2308917803[T65,L1051,R44,V2186]高息揽储->正常还本付息->老乡们奔走相告->更高的息揽储->老乡们几倍于前面的资金跟进…(循环一段时间,有长有短)…->突然告知不能还本付息->老乡们挤兑->老总站台,出补偿方案->方......
  • European software vendors ranking 2012 (zz)
    Europeansoftwarevendorsranking2012//z2013-07-1214:08:28IS2120@BG57IV3.T849537077.K[T62,L646,R24,V1099]欧洲最大100家软件企业公司一百强100强软件公司世界欧洲美国最大营业额利润排名RankCompanyPublic ?CountryofHQlocationSoftwarereven......
  • 保护眼睛——设置WIN7和XP 窗体、Chrome、IE网页背景颜色(zz)
    保护眼睛——设置WIN7和XP窗体、Chrome、IE网页背景颜色//z2013-09-2121:03:55IS2120@BG57IV3T1254112016.K.F1916596678[T3,L48,R1,V13]淡绿色(绿豆沙):#C7EDCC绿豆沙:199,237,204 米  色:245,245,220象牙白:250.255.240麦色:245,222,179眼科医生推荐的颜色是柔和的淡绿......
  • 中国字 (zz)
    1.祯《大雅·文王之什·文王》:“王国克生,维周之桢”,维:维系;桢:支柱,栋梁。后文《周颂·维清》中还有“维周之祯”,祯是吉祥的意思。文王文王在上,於昭于天。周虽旧邦,其命维新。有周不显,帝命不时。文王陟降,在帝左右。亹亹文王,令闻不已。陈锡哉周,侯文王孙子。文王孙......
  • CString TO Double (zz)
    //z2013-10-2115:01:30IS2120@BG57IV3T3345574402.K.F3396121938[T3,L303,R3,V37]1.atlCString转换成double浮点数A CString canconverttoan LPCTSTR,whichisbasicallya constchar* (constwchar_t*atof():CStringthestring("13.37");doubled=a......
  • 2012中国软件业务收入百强企业发布 (zz.IS2120)
    2012年(第十一届)中国软件业务收入前百家企业名单//z2012-10-0320:27:13IS2120@BG57IV3.T1002468230.K 单位:万元                      序号企业名称软件业务收入序号企业名称软件业务收入1华为技术有限公司850384926国电南京自动化股份有限公司26675......
  • 常规游戏编程指导规范 (zz)
       章节名:常规游戏编程指导规范   2012-03-2120:48:41鱼雷(左手程序右手诗)//z2012-4-1017:34:53PMIS21201.对你所做的工作进行备份    不备份的代价是巨大的,重新编写角色AI和冲突检测就是悲剧2.开始游戏项目时要进行良......
  • How to: Configure Express to accept remote connections zz
    作者写于2005,针对的是sqlserver2005express.Updated配置sqlserver2005以允许远程连接TheinformationinthispostingissupersededbythefollowingKBArticle:914277 HowtoconfigureSQLServer2005toallowremoteconnectionshttp://support.microsoft.com/d......
  • 站在巨人的肩膀上 -- 书籍推荐 (zz)
    站在巨人的肩膀上--书籍推荐//z2012-5-1316:39:07PMIS212随着这个世界越来越依赖我们的实践,作为计算机行业的从业人员,对计算机行业的science实在有必要给与应有的尊重。行动的第一步,就是阅读一些经典的著作,掌握前人/前辈/行业大家们总结出来的知识和行之有效的实践,在......