oracle資料庫操作語句
阿新 • • 發佈:2020-11-25
1 -- 建立student表
2 create table student (
3 id number,
4 name vachar2(50),
5 age number(3),
6 test vachar2(20)
7
8 );
9
10 -- 修改表結構 (給student表新增兩列)
11 alter table student add (
12 clazz vachar2(20),
13 address vachar2(50),
14 );
15
16 -- 修改列型別 (修改班級欄位的資料型別為number型別)
17 alter table person modify clazz number(2);
18
19 --修改列名稱 (修改班級欄位的列名從clazz -> grade)
20 alter table student rename column clazz to grade;
21
22 -- 刪除一列 (刪除test欄位)
23 alter table student drop column test;
24
25 -- 給相應列新增comments註釋
26 comments on column student.id is '學生主鍵';
27 comments on column student.name is '學生姓名';
28 comments on column student.age is '學生年齡';
29 comments on column student.address is '學生地址';
30 comments on column student.grade is '學生班級';
31
32 -- 給學生表新增主鍵約束(名字隨便取:PK_STUDENT_ID)(constraint:約束)
33 alter table student add constraint PK_STUDENT_ID primary key (ID);