創建表: create table 表名 ( 欄位名1 欄位類型 預設值 是否為空 , 欄位名2 欄位類型 預設值 是否為空, 欄位名3 欄位類型 預設值 是否為空, ...... ); 創建一個user表: create table user ( id number(6) primary key, ...
創建表:
create table 表名 (
欄位名1 欄位類型 預設值 是否為空 ,
欄位名2 欄位類型 預設值 是否為空,
欄位名3 欄位類型 預設值 是否為空,
......
);
創建一個user表:
create table user (
id number(6) primary key, ---主鍵
name varchar(50) not null, ---姓名 不為null
sex varchar2(6) default '男' check ( sex in ('男','女')) ---性別 預設'男'
);
修改表名:
rename 舊表名 to 新表名;
rename user to newuser;
刪除表:
delete from 表名;
delete刪除數據是一條一條的刪除數據,後面可以添加where條件,不刪除表結構。註意:如果表中有identity產生的自增id列,delete from後仍然從上次的數開始增加。
truncate table 表名;
truncate是一次性刪掉所有數據,不刪除表結構。註意:如果表中有identity產生的自增id列,truncate後,會恢復初始值。
drop table 表名;
drop刪除所有數據,會刪除表結構。
修改表:
添加新欄位:
alter table 表名 add(欄位名 欄位類型 預設值 是否為空);
alter table user add(age number(6));
alter table user add (course varchar2(30) default '空' not null);
修改欄位:
alter table 表名 modify (欄位名 欄位類型 預設值 是否為空);
alter table user modify((age number(8));
修改欄位名:
alter table 表名 rename column 列名 to 新列名;
alter table user rename column course to newcourse;
刪除欄位:
alter table 表名 drop column 欄位名;
alter table user drop column course;