asdtiang的博客 感谢blogjava提供的博客交流平台

oracle命令学习笔记

Posted on 2010-01-12 17:40 asdtiang 阅读(738) 评论(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美元)