Oracle数据库 增删改查 基础知识

1.创建表

CREATE TABLE table_name (
字段名称 字段的数据类型 [字段的约束],
字段名称 字段的数据类型 [字段的约束], … );

2.修改表

2.1修改表名

alter table 原表名 rename to 新表名;

2.2增加字段

alter table 表名 add 字段名 类型;
比如:
alter table sudent add name varchar2(10);

2.3修改字段

alter table 表名 modify 数据名称 数据类型;
比如:
alter table xc01 modify info number(3);

3.删除表

drop table 表名;

4.插入、更新数据

4.1插入字段

插入字段 :
insert into table_name(field1,field2,…) VALUES(val1,val2,…);
比如:insert into xc01(xcname,xcage,xcscore,info)
values (‘sss’,23,100,100);

4.2更新数据

UPDATE 表名 SET field1=val1,field2=val2,… WHERE condition

比如:update xc01 x
set x.xcage=22 ,x.xcname=‘xxxx’;

4.3删除数据

DELETE FROM table_name WHERE CONDITION

比如:delete from xc01 t where t.xcname=‘xxxx’;
commit;

4.4查询数据

select * from xc01 c where c.xcname=‘xxxx’;

注:oracle 数据库,需要手动提交事务,可以在增删改语句后,添加 commit 语句

代码如下:


--1.创建表名为xc的表格
create table xc (
       xcname varchar(10) primary key,
       xcage  number(2)   not null,
       xcscore number(10)   not null  
)
select *from xc01;
--2.修改表
--2.1修改表名
alter table xc rename to  xc01;
--2.2增加字段
alter table xc01 add info varchar2(10);
--2.3修改字段
alter table xc01 modify info number(3);

--3删除表
drop  table xc01;

--oracle 数据库,需要手动提交事务,可以在增删改语句后,添加 commit 语句
--4.插入数据
insert into xc01(xcname,xcage,xcscore,info)
 values ('sss',23,100,100);
--5.更新数据
update xc01 x
            set x.xcage=22 ,x.xcname='xxxx';
            
--6.删除数据:
delete from xc01 t where t.xcname='xxxx';
--7.查询数据
select * from xc01 c where c.xcname='xxxx';
           
 
 
 








猜你喜欢

转载自blog.csdn.net/LL__Sunny/article/details/108899852