


Xiaobai's second level of learning Oracle: Creation of the first Oracle database table
Nowadays, in actual work, creating tables in the database is often used. In this article, the editor mainly shares with you how to create tables in the database through SQL statements. First, use plsql to connect to the oracle database and ensure that the following services are enabled.
Our requirements for creating a table this time are: create a class table, and a Zhang student table.
1. First, the class table serves as the main table, which is the so-called primary key. In the main table, the constraints we use here are primarykey and not null
create table classinfo( classid number(2) primary key, classname varchar(10) not null );
sql analysis:
--create table The keyword to create the table
--classinfo is the name of the created table
--classid is the class table The id data type is number(2). We give it 2 lengths by default. We set the class id as the primary key to facilitate other foreign key associations.
--classname is the class name data type It is character type varchar(10). We have given a default length of 10 characters. The constraint of the class name is that it cannot be empty
Execute the sql statement:
# The classinfo table was created successfully.
2. Then we create a foreign key, that is A table associated with the primary key. Please see the following SQL statement 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='男' or studentsex='女'), studentage number(2) not null, studenttel number(11) unique, studentaddress varchar(50) default '上海', classid number(2) references classinfo(classid) );
SQL statement analysis:
--create table keyword to create a table
--studentinfo(); is the table name used to create the student information table
--studentid (student id) The constraint is the primary key primary key
--studentname (student name) The constraint is not null
--studentsex (student gender) The constraint is check
--studentage (student age) The constraint is not null
--studenttel (student phone number) The constraint is unique
- -studentaddress (student address) are the column names in the student table.
The student table studentinfo is created.
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='男' or studentsex='女'), studentage number(2) not null, studenttel number(11) unique, studentaddress varchar(50) default '上海', classid number(2) references classinfo(classid) );
At this point, the class table and student table we created have been demonstrated. Isn’t it very simple?
[Recommended course: Oracle Video Tutorial]
The above is the detailed content of Xiaobai's second level of learning Oracle: Creation of the first Oracle database table. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.
