当前位置:Gxlcms > 数据库问题 > oracle数据库创建表

oracle数据库创建表

时间:2021-07-01 10:21:17 帮助过:178人阅读

create table studentinfo(
       studentid number(2) primary key,
       studentname varchar(10) not null,
       studentsex char(2) check(studentsex=‘男‘ or studentsex=‘女‘),
       studentage number(2) not null,
       studenttel number(11) unique,
       studentaddress varchar(50) default ‘上海‘,
       classid number(2) references classinfo(classid)
       );
技术图片

 sql语句解析:

--create table 创建表的关键字

--studentinfo();是创建学生信息表的表名

--studentid(学生id)          约束是主键 primary key

--studentname(学生姓名)    约束是  not  null  

--studentsex(学生性别)   约束是 check 

--studentage(学生年龄)   约束是 not null 

--studenttel(学生电话)          约束是 unique

--studentaddress(学生地址)      分别为学生表中的列名。

 学生表studentinfo建立完成。

技术图片

 

 完整的sql语句如下:

技术图片
create table classinfo(
       classid number(2) primary key,
       classname varchar(10) not null       
       );
       
create table studentinfo(
       studentid number(2) primary key,
       studentname varchar(10) not null,
       studentsex char(2) check(studentsex=‘男‘ or studentsex=‘女‘),
       studentage number(2) not null,
       studenttel number(11) unique,
       studentaddress varchar(50) default ‘上海‘,
       classid number(2) references classinfo(classid)
       );
技术图片

 到此,我们创建的班级表和学生表就演示完了,是不是很简单呢?

oracle数据库创建表

标签:tin   地址   演示   unique   主表   arc   建表   number   外键   

人气教程排行