- 創建表
create table A( aid number(2) not null, aname varchar2(4), asal number(7,2) );
- 增加數據(插入)
insert into a(aid,aname,asal) values(1,'張三',1000.5); insert into a values(1,'張三',1000.5);
- 修改數據(更新)
update <表名> set <列名=更新值> [where <更新條件>]
例:update tongxunlu set 年齡=18 where 姓名='藍色小名'
- 刪除數據
【刪除<滿足條件的>行數據】delete from <表名> [where <刪除條件>]
例:delete from a where name='開心朋朋'(刪除表a中列值為開心朋朋的行)
【刪除整個表數據】truncate table <表名>
例:truncate table tongxunlu
注意:刪除表的所有行,但表的結構、列、約束、索引等不會被刪除;不能用語有外建約束引用的表
【刪除整個表】drop table 表名稱
例:drop table a;
- 查詢數據
select * from a;
select 字段 from 表名 where 條件
- 增加字段語法
alter table tablename add (column datatype [default value][null/not null],….);
說明:alter table 表名 add (字段名 字段類型 默認值 是否為空);
例:alter table sf_users add (HeadPIC blob);
例:alter table sf_users add (userName varchar2(30) default '空' not null);
- 修改字段的語法
alter table tablename modify (column datatype [default value][null/not null],….);
說明:alter table 表名 modify (字段名 字段類型 默認值 是否為空);
例:alter table sf_InvoiceApply modify (BILLCODE number(4));
- 刪除字段的語法
alter table tablename drop (column);
說明:alter table 表名 drop column 字段名;
例:alter table sf_users drop column HeadPIC;
- 字段的重命名
說明:alter table 表名 rename column 列名 to 新列名 (其中:column是關鍵字)
例:alter table sf_InvoiceApply rename column PIC to NEWPIC;
- 表的重命名
說明:alter table 表名 rename to 新表名
例:alter table sf_InvoiceApply rename to sf_New_InvoiceApply;
- 實現將一個表的數據插入到另外一個表
1.第一種情況
1》如果2張表的字段一致,並且希望插入全部數據,可以用這種方法:
INSERT INTO 目標表 SELECT * FROM 來源表;
2》比如要將 articles 表插入到 newArticles 表中,則是:
INSERT INTO newArticles SELECT * FROM articles;
3》如果只希望導入指定字段,可以用這種方法:
INSERT INTO 目標表 (字段1, 字段2, ...) SELECT 字段1, 字段2, ... FROM 來源表;
2.第二種情況
1》如果將一個表的數據放在另外一個不存在的表:
select * into 目標不存在的表 from 來源表
2》如果只希望導入指定字段,可以用這種方法:
select 字段1,字段2,... into 目標不存在的表 from 來源表