Oracle基礎 建表語句(DDL)

2021-07-09 10:07:11 字數 2379 閱讀 7953

1.建立表

語法:create table table_name(

filed_name datatype not null,

filed_name datatype not null,

filed_name datatype,

filed_name datatype not null,

constraint pk_name primary key (filed_name)

using index tablespace tablespace_name1

)tablespace tablespace_name2;

comment on table table_name is 'comment';

comment on column table_name.filed_name is 'comment';

comment on column table_name.filed_name is 'comment';

comment on column table_name.filed_name is 'comment';

comment on column table_name.filed_name is 'comment';

示例:--1.建表

--學生表

create table student(

student_id number(12) not null,

stu_name varchar2(255) not null,

age number(6),

*** char(1) not null,

constraint pk_student primary key (student_id)

using index tablespace idx_cc

)tablespace tab_cc;

comment on table student is '學生表';

comment on column student.student_id is '學生標識';

comment on column student.stu_name is '學生姓名';

comment on column student.age is '學生年齡';

comment on column student.*** is '學生性別';

commit;

--課程表

create table course(

course_id number(12) not null,

course_name varchar2(255) not null,

constraint pk_course primary key (course_id)

using index tablespace idx_cc

)tablespace tab_cc;

comment on table course is '課程';

comment on column course.course_id is '課程標識';

comment on column course.course_name is '課程名稱';

commit;

--學生課程表

create table stu_course(

student_id number(12) not null,

course_id number(12) not null,

constraint pk_stu_course primary key (student_id,course_id)

using index tablespace idx_cc

)tablespace tab_cc;

comment on table stu_course is '學生課程表';

comment on column stu_course.student_id is '學生標識';

comment on column stu_course.course_id is '課程標識';

commit;

alter table stu_course add

constraint fk_stu_course_student foreign key (student_id) 

references student(student_id);

alter table stu_course add 

constraint fk_stu_course_course foreign key(course_id)

references course(course_id);

commit;

2.刪除表

語法:drop table table_name;

示例:drop table student;

Oracle基礎 建表語句(DDL)

1.建立表 語法 create table table name filed name datatype not null,filed name datatype not null,filed name datatype,filed name datatype not null,constraint...

Oracle 建表語句

create table table name id numner 12 text verchar2 255char not null char型別,乙個漢字佔乙個長度 pid varchar2 32 byte notnull byte型別,utf8乙個漢字佔大約兩個長度 status number...

Oracle標準建表語句

create table 建表 create table outln.customer id varchar2 32 default sys guid not null,cust id varchar2 64 cust name varchar2 255 id no varchar2 64 mobi...