Get the App
SLTechnology News&Howtos  ›  Database  › 

How to create oracle database tables

Shulou Source: shulou.com Published: 2022-05-31 23:55:37 10月25日 Update

This article mainly introduces how to create an oracle database table, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Our need to create a table this time is to create a class table and a student table.

1. First of all, the class table is the main table, that is, the so-called primary key. The constraints we use here in the main table are primarykey and not null

Create table classinfo (classid number 2) primary key, classname varchar 10 not null)

Sql parsing:

-- create table keyword for creating a table

-- classinfo is the name of the table created

-- classid is the id data type of the class table is number (2). We default to 2 lengths. We set the class id as the primary key to facilitate other foreign key associations.

-- classname is the class name data type is character type varchar (10). We give the default length of 10 characters, and the class name constraint cannot be empty.

Execute the sql statement:

The classinfo table was created successfully.

two。 Then we create a foreign key, that is, a table associated with the primary key, and see the sql statement below for the data types and constraints used.

Create table studentinfo (studentid number (2) primary key, studentname varchar (10) not null, studentsex char (2) check (studentsex=' male'or studentsex=' female'), studentage number (2) not null, studenttel number (11) unique, studentaddress varchar (50) default 'Shanghai', classid number (2) references classinfo (classid))

Sql statement parsing:

-- create table keyword for creating a table

-- studentinfo (); is the table name that creates the student information table

-- studentid (student id) constraint is the primary key primary key

-- studentname (student name) constraint is not null

-- studentsex (student gender) constraint is check

-- studentage (student age) constraint is not null

-- studenttel (student phone) constraint is unique

-- studentaddress (student address) is the column name in the student table.

The student form studentinfo has been established.

The complete sql statement is as follows:

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=' male'or studentsex=' female'), studentage number (2) not null, studenttel number (11) unique, studentaddress varchar (50) default 'Shanghai', classid number (2) references classinfo (classid))

At this point, the class table and student table we created are over.

Thank you for reading this article carefully. I hope the article "how to create oracle database tables" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Students classes data articles types statements databases that is keys keywords names characters length Shanghai associations character types success value information interests Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB NVidia Huawei Shulou Information MySQL