We will continue using sqlplus from the previous lesson to create tables inside sqlplus. You may also use SQL Developer, a more‑powerful tool for table creation with a graphical interface. However, Oracle on Linux is frequently operated without a GUI. That is why getting comfortable with SQL Plus is beneficial.
Create the student data table and verify that the table has been created successfully.
Table‑Creation SQL Statement
create table student(
id number(10) primary key,
name varchar2(20) not null,
sex varchar2(2) default 'M' check(sex in('M','F'))
);Code language: JavaScript (javascript)
Explanation of Column Constraints
id number(10) primary key: Primary key, non‑null and holds unique numeric valuesname varchar2(20) not null: Student name, cannot be nullsex varchar2(2) default 'M' check(sex in('M','F'))
- Default value:
M - Check constraint: Only M / F are allowed for gender; other values cannot be inserted
Success prompt:Table created.
Verify Whether the Table Is Created
Query Statement
SELECT table_name FROM user_tables ORDER BY table_name;
Output after execution:
TABLE_NAME
------------------------------
STUDENT
The appearance of STUDENT in the result list means the table is ready.
Execution Example
SQL> create table student(
id number(10) primary key,
name varchar2(20) not null,
sex varchar2(2) default 'M' check(sex in('M','F'))
);
Table created.
SQL> SELECT table_name FROM user_tables ORDER BY table_name;
TABLE_NAME
------------------------------
STUDENT
SQL>Code language: JavaScript (javascript)
The above is the full execution log. When copying and running the code, keep proper spacing and avoid joining words together.
Create table
Previous: Create user