asdtiang的博客 感謝blogjava提供的博客交流平臺

          oracle命令學習筆記

          Posted on 2010-01-12 17:40 asdtiang 閱讀(755) 評論(0)  編輯  收藏

          刪除/添加外鍵約束,
          ALTER TABLE 表名
          ADD CONSTRAINT 約束名 --可以是任意合法標示符
              UNIQUE (字段列表) -- 字段列表可以使多個字段,用','分開。
          添加唯一約束
          alter table t add constraint uk_t_1 unique (a,b);
          alter table agent add constraint agent_uk unique(agent_id);

          刪除/添加列
          再把原表中的   aColumn,   bColumn   列刪除    
          alter   table   srcTable   drop   column   aColumn;   
          alter table area add (areaaddress varchar(20));
          更改列名
          alter   table   OPERATOR   rename   column   PSWD   to   PSWD1;  

          alter table "class" add constraint CLASS_PK primary key( "sid" ASC )
          更新字段值
          update ems_edi_dcr_img set fact_remain_qty=23946.57 where g_no=19;
          update company set contime=to_date('2005-9-16','yyyy-mm-dd') where companyid=2;
          更改表名
          ALTER TABLE old_table_name RENAME TO new_table_name;

          清屏
          clear   screen
          日期插入
          insert   into   test   (UserID,UserName,UserFlag,InputDate)  
          values(31,'Test',1,to_date('2005-9-16','yyyy-mm-dd'));

          更改默認值:
          sql server
          alter table tablename alter column columnname int(10) not null default '20'

          oracle
          alter table tablename modify(zhuan int(10) not null default '20');
          alter table company modify (areaid number(38) not null default 1);

          alter table custom add constraint custom_sing_for foreign key (presonDo) references sing_for(name);

          刪除數據

            DELETE語句用來從表中刪除一行或多行數據,該命令包含兩個語句:

             1、關鍵字DELETE FROM后跟準備從中刪除數據的表名。

             2、WHERE后跟刪除條件

          DELETE FROM po_lines
          WHERE ship_to_state IN ('TX','NY','IL')
          AND order_date
          delete from agent where agent_id='2';

          delete from card where card_id='5';

          ORACLE中的模糊查詢是靠LIKE操作符來完成的。
          現在我們來看一下LIKE操作符使用過程中的一些具體的問題
          %:代表0個或者多個字符
          _(下劃線):代表一個字符
          比如:
          (1)
          select ename from emp
          where ename like 'S%';
          上面這個例子查詢出的是以大寫S為名字首字母的員工的員工姓名
          (2)
          select ename from emp
          where ename like '_A%';
          上面的這個例子中,匹配的就是名字中第二個字母為A的那些員工

          除了上面兩種基本的用法外,我們可能還會碰到這樣的問題,比如在員工的名字里就包含有‘%’
          或者'_',那么我們該怎么辦呢?
          比如假如有一個員工的姓名為tom_cat,那么我們如何查詢出和這個員工相關的一些信息呢?
          我們的SQL語句應該這樣來寫;
          select * from emp
          where ename like '%\_%' escape '\';

          select company.company_id 公司編號,company_month.return_money 返回錢 from company,company_month where company_month.month=7 and company_month.year=2009



          天蒼蒼,野茫茫,風吹草底見牛羊

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          posts - 80, comments - 24, trackbacks - 0, articles - 32

          Copyright © asdtiang

          asdtiang的博客 PaidMailz
          點擊廣告網賺A(每天4個廣告,每個0.0025美元,一個搜索廣告0.03美元)
          主站蜘蛛池模板: 定边县| 临澧县| 光山县| 定结县| 玛沁县| 广灵县| 景宁| 台州市| 蓬溪县| 江都市| 高唐县| 潼关县| 马山县| 加查县| 盈江县| 中山市| 潜山县| 泰兴市| 玉环县| 沁水县| 环江| 麻城市| 伊川县| 道真| 嘉黎县| 七台河市| 绥德县| 东阿县| 沈阳市| 紫金县| 怀安县| 千阳县| 乳源| 安泽县| 浦城县| 鹰潭市| 荣成市| 衡东县| 舞钢市| 嵊泗县| 汾阳市|