建表及修改表

2021-09-02 13:48:21 字數 746 閱讀 8050

1.建表

例子:——學生表

sql>create table student (——表名

xh number(4),——學號

xm varchar2(20),——姓名

*** char(2),——性別

birthday date,——出生日期

sal number(7,2)——獎學金

);——班級表

sql>create table classes (

classid number(2),

cname varchar2(20));

2.修改表

1)新增乙個字段

sql>alter table student add(classid number(2));

2)修改欄位的長度

sql>alter table student modify (xm varchar2(30));

3)修改欄位的型別/或是名字(不能有資料)

sql>alter table student modify(xm char(30));

4)刪除乙個字段(在實際開發中不建議使用)

sql>alter table student drop column sal;

5)修改表的名字

sql>rename student to stu;

6)刪除表

sql>drop table student;

3.檢視表結構

sql>desc 表名

建表並修改表約束

主鍵約束 primary key not null check unique 唯一約束 create table student 學生表 xh number 4 constraint pk stu primary key,學號主鍵 xm varchar2 10 constraint nn stu n...

hive建表及表操作

建表的三種形式 1.直接建表 create external table if not exists tab name row 1 type,row 2 type partition by row 3 type,type 4 type row format delimited fields term...

在Oralce建表並修改表結構

學生表 student create table student 學生表 xh number 4 學號 xm varchar2 10 姓名 char 2 性別 birthday date,日期 sal number 7,2 獎學金 班級 class create table class 班級表 cl...