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';
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/153012.html
標籤:其他
