In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you how oracle database is to create tables, concise and easy to understand, absolutely can make your eyes shine, through the detailed introduction of this article I hope you can gain something.
In practice, creating tables in a database is often used. What about us today? The main thing is to share with you how to create tables in the database through sql statements. In fact, creating a table is very simple, you only need to clarify the data types and constraints of the database, and the rest will be said. And then, let's start my show. First, use plsql to connect to oracle database and make sure the following services are turned on.
Our requirements for creating tables this time are: create a class table, and a student table.
1. First of all, the class table is the main table, which is the so-called primary key. The constraints we use here in the main table are primarykey and not null (but not limited to these)
create table classinfo(classid number(2) primary key,classname varchar(10) not null );
SQL analysis:
--create table keyword
--classinfo is the name of the table created
--classid is the id of the class table. The data type is number(2). We give 2 lengths by default. We set the class id as the primary key to facilitate other foreign key associations.
--classname is class name data type is character type varchar(10), we give the default 10 characters length, class name constraint is not empty
Execute SQL statement:
Classinfo table created successfully.
2. Then we create a foreign key, that is, a table associated with the primary key, using the data types and constraints shown in the sql statement below.
create table studentinfo(studentid number(2) primary key,studentname varchar(10) not null,studentsex char(2) check(studentsex ='M ' or studentsex ='F'),studentage number(2) not null,studenttel number(11) unique,studentaddress varchar(50) default 'Shanghai', classification number(2) references classinfo(classification));
SQL statement parsing:
--create table keyword
--studentinfo(); is the name of the table creating the student information table
--studentid constraint is primary key primary key
--studentname constraint is not null
--studentsex constraint is check
--studentage constraint is not null
--studenttel constraint is unique
--studentaddress is the column name in the student table.
Student table studentinfo setup completed.
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, we created the class table and student table demonstration is over, is it very simple?
That's how oracle database creates tables. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.