Oracle basic (7) data table, oracle basic data table
1. Create a table
Syntax:
Create table [schema.] table
(Column datatype [, column datatype [,...]);
Note:
Create table: the keyword used to CREATE a TABLE.
Schema: indicates the owner of the object, that is, the name of the schema. If you create a table in your schema, you can leave the name of the owner unspecified.
Table: The table name.
Column: column name
Datatype indicates the data type and width of the column.
Example:
-- Create table user (id number not null, username varchar2 (20) not null,
Userpass varchar2 (20) not null
)
If you create a user table, the following naming rules must be followed.
1. It indicates that the first letter should be a letter.
2. You cannot use Oracle reserved words to name a table.
3. the maximum length is 30 characters.
4. Different tables in the same user mode cannot have the same name.
4. You can use money, numbers, and letters, but not spaces or single quotes.
5. The table name, column name, user name, and other object names in Oracle are case-insensitive. The system automatically converts them to uppercase and lowercase.
Ii. modify a table
Alter table: a command to modify the TABLE structure. When you need to add new columns to the original TABLE, modify the original columns, delete the original columns, add constraints, and delete constraints, you can use the alter table command.
Modify the syntax of an existing column:
Alter table <tablename> MODIFY (column definition ...);
Example:
Change the length of the user name and password to 50;
ALTER TABLE t_userMODIFY (username VARCHAR2(50),userpass VARCHAR2(50))
Syntax for adding a new column:
Alter table <tablename> ADD (column definition ...);
Example:
Add phone and address
ALTER TABLE t_userADD (tel VARCHAR2(20),address VARCHAR2(100))
Syntax for deleting existing columns in the table:
Alter table <tablename> drop column colmn;
Example:
Delete phone and address
ALTER TABLE t_userDROP (tel,address)
Iii. delete a table
Syntax:
Drop table <tablename>;
Example: delete a user table
Drop table t_user;