Oracle脚本笔记
//創建一個表
create table? 表名
(字段名1 varchar2(20) not null);
//多個用 , 隔開
//添加字段
alter table 表名
add (字段名2 varchar2(30) default ‘初始值' not null);
?COMMENT ON COLUMN 表名.字段名 IS '注釋';
//修改一個字段
alter table 表名
modify (舊字段名 varchar2(16) default ‘新字段名');
或
alter table 表名 rename column 舊字段 to 新字段;
//刪除一個字段
alter table 表名? drop column 字段名;
//修改列的名稱
ALTER TABLE 表明 RENAME COLUMN 舊名 to 新名;
//重命名表
ALTER TABLE 舊表名 RENAME TO 新表名;
//向表中添加主鍵約束
alter table 表名 add constraint pk_表名 primary key(主鍵);
//======================================
1、創建表的同時創建主鍵約束
(1)無命名
復制代碼 代碼如下:
create table student (
studentid int primary key not null,
studentname varchar(8),
age int);
(2)有命名
復制代碼 代碼如下:
create table students (
studentid int ,
studentname varchar(8),
age int,
constraint yy primary key(studentid));
2、刪除表中已有的主鍵約束
(1)無命名
可用 SELECT * from user_cons_columns;
查找表中主鍵名稱得student表中的主鍵名為SYS_C002715
alter table student drop constraint SYS_C002715;
(2)有命名
alter table students drop constraint yy;
轉載于:https://www.cnblogs.com/renpei/p/5457753.html
總結
以上是生活随笔為你收集整理的Oracle脚本笔记的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: fastjson与spring mvc整
- 下一篇: 双塔