Database functions: 1. Structured Storage of large amounts of data. 2. Maintain data consistency effectively. 3. Facilitate Intelligent Analysis and generate new useful information. 4. Meet Application Sharing and security requirements. A relational database is composed of a group of tables. 2. Each row in the table is a record ). 3.
Database functions: 1. Structured Storage of large amounts of data. 2. Maintain data consistency effectively. 3. Facilitate Intelligent Analysis and generate new useful information. 4. Meet Application Sharing and security requirements. A relational database is composed of a group of tables. 2. Each row in the table is a record ). 3.
Database functions: 1. Structured Storage of large amounts of data. 2. Maintain data consistency effectively. 3. Facilitate Intelligent Analysis and generate new useful information. 4. Meet Application Sharing and security requirements.
A relational database is composed of a group of tables. 2. Each row in the table is a record ). 3. Each column in the table is called a field ).
Global Database Name: The name that uniquely identifies the Oracle database.
SID: a reference to the Oracle database. Scott account: Example account. The default password is tiger.
Method for connecting to the database: Enter c:/> sqlplus in the DOS environment and connect as prompted. c:/> sqlplus username/password @ database name connects to the specified database. c: /> sqlplus/nolog c:/> connect user name/password @ database name.
In the Oracle system, tablespaces and data files are the basic elements of the Oracle database structure.
Oracle databases store information in an organized manner. They have two mutually related physical storage structures and logical structures. The physical storage structure is a real data storage unit. It mainly consists of data files (files storing database data) and log files (records changes to the database) and control files (binary files that record the physical structure of the database). The logical storage structure is a conceptual structure of data. It mainly consists of tablespaces,
Table, row, and other concepts.
A Tablespace is a logical unit of data stored in Oracle databases. The logical disk space used to store database tables, indexes, and other objects is called a Tablespace ). A database consists of multiple tablespaces, and a tablespace consists of multiple data files.
In a program, you can organize SQL statements to be sent to the database, and the database performs corresponding operations.
SQL language classification: 1. Data Definition Language (DDL), defining and managing various objects in the database (CREATE statements are used to CREATE objects, ALTER statements are used to modify objects, and DROP statements are used to delete objects ). 2. Data Operation Language (DML ), operate on the data contained in the database object (the INSERT statement is used to INSERT a row of data into the data table, the UPDATE statement is used to UPDATE or modify the values of one or more rows, and the DELETE statement is used to DELETE one or more rows in the data table row data, you can also delete the data records in the table ). 3. Data Control Language (DCL), which controls the operation permissions of database objects (GRANT the database object permission to the user or user group, and REVOKE the REVOKE statement permission ).
Create a tablespaceSyntax:
CREATETABLESPACE tablespacename refers to the name of the tablespace to be created
DATAFILE 'filename' [SIZE integer [K | M] DATAFILE specifies one or more data files that constitute the tablespace. Use commas to separate multiple data files, filename refers to the path and name of the data file in the tablespace. SIZE is the file SIZE. K is used to indicate the SIZE of kilobytes. M is used to specify the SIZE of megabytes.
[AUTORXTEND [OFF | ON]; The AUTOEXTEND clause is used to enable or disable automatic extension of data files.
For example:
create tablespace myhrdatafile 'myhr.dbf'size 100M autoextend on;
The create user command in Oracle is usedCreate a new userEach user has a default tablespace and a temporary tablespace. If this parameter is not specified, Oracle sets USERS as the default tablespace. TEMP indicates the temporary tablespace.
The syntax for creating a user is as follows:
CREATEUSER <用户名> IDENTIFIED <口令> The user name and password must be specified.
DEFAULTTABLESPACE <表空间名> Default tablespace indicates the default tablespace.
TEMPORARYTABLESPACE <临时表空间名> Indicates the temporary tablespace you have created.
QUOTA <空间大小> ON <空间名称>
For example:
create user myhr identified by myhrdefault tablespace myhr temporary tablespace tempquota unlimited on myhr;
How to obtain permissions for Oracle users1. The Administrator directly grants permissions to the user. 2. The Administrator grants permissions to the role and then grants the role to one or more users. Permissions can be divided into system permissions (system permissions are the right to execute certain system-level operations in the database, or to execute certain operations for certain types of objects .) And object permissions (that is, the user's permissions on objects in a specific database ). Common system permissions: create session connects to the database, create table creates tables, CREATEVIEW creates views, and create sequence creates sequences;
A role is a set of one or more permissions. A role can be granted to any user or revoked from the user. Granting permissions to users through roles can greatly simplify the workload of database administrators.
Authorization method: GRANT permission | role TO user name; cancel authorization: REVOKE permission | role FROM user name;
For example:
grant connect,resource to myhr;
Both connect and resource are built-in database roles.
Field Type: 1. Text Data Type: char (used to describe fixed-length bytes of data, up to 2000 bytes. It is often used to store a small amount of text), varchar2 (used to describe variable-length character data, up to 4000 bytes), long (used to save data of up to 2 GB size, but often replaced by the clob type ). 2. Numeric data type: number is used to store Integer or floating point values. binary_integer is an Integer in PL/SQL. It can only be in PL/SQL, and the speed is slower than Integer; binary_double is a new data type provided by Oracle10G. It is used to store a 64-bit double precision as a floating point number. 3. The date data type is used to store the date and time, data is used to store the date and time data in the table. Oracle databases store dates in their own format and use a fixed length of 7 bytes. Each byte is stored in Century, year, month, day, hour, minute, and second. The SYSDATE function in Oracle returns the current date and time; timestamp is used to store the hour, minute, and second values of the year, month, day, and time of the date (the second value is accurate to the six digits after the decimal point. This data type includes time zone information ), the SYSTIMESTAMP function returns the current date, time, and time zone. 4. The big object data type is used to store large image files or text files with formats, such as Word documents, audio files, and videos. clob is used to store large volumes of text, A table can have multiple clob fields. Blob is used to store binary objects, such as parts.
Create a tableSyntax: CREATETABLE table name (field Name field type );
For example:
create table Student( stu_id varchar2(11), name varchar2(10), age number, class varchar2(10), description varchar2(500));
View the table structure. You can enter the DESC table name in the Command window;
For example:
desc Student;
Data IntegrityIt refers to the data accuracy in the database.
To achieve data integrity, the database needs to do the following two aspects: 1. Check whether each row of data meets the requirements. 2. Check whether each column of data meets the requirements.
Oracle Database provides the following four types of constraints: 1. entity integrity constraints. 2. Domain integrity constraints. 3. integrity constraints. 4. Custom integrity constraints.
Entity integrity constraints: each row of data in the table must reflect different entities and cannot have the same data rows. They are generally implemented through primary key constraints and unique constraints.
Add primary keyCONSTRAINT Syntax: alter table name add constraint name primary key (field name );
For example:
alter table STUDENT add constraint PK_STU_ID primary key (STU_ID);
Syntax for adding a unique constraint: alter table name add constraint name UNIQUE (field name
For example:
alter table student add constraint UQ_DESCRIPTION unique(description);
Domain integrity constraints indicate the input validity of a given field. You can restrict the data type, check constraints, input formats, default values, non-empty constraints, and other methods.
For example:
alter table student add constraint chk_age check(age>0);
When you enter or delete data rows, the reference integrity constraints are used to maintain the defined relationships between tables. For example:
Class info table: Student info table:
|
Class No. (cla_id) |
Class Name (cla_name) |
|
C001 |
2012 Computer Class 1 |
|
C002 |
2012 computer Second Class |
|
C003 |
2012 Mathematics Class 1 |
|
Student ID (stu_id |
Class No. (stu_cla_id |
Student name (stu_name) |
|
S101 |
C001 |
Lu Fengxian |
|
S102 |
C102 |
Zhang wenyuan |
|
S201 |
C002 |
Liu Xuande |
|
S301 |
C003 |
Cao Mengde |
When managing student information, one table is used to store the class information, that is, the class information table. The other table is used to store the student information, that is, the student information table.
In addition, the two tables are associated by class numbers. Here we generally convert the class information into the primary table, and the student information table is called a subtable. When you forcibly reference integrity, Oracle Database prohibits users from performing the following operations: 1. When the master table is not relevant
When associating records, add the records to the relevant table. That is to say, the student information table cannot contain the class numbers that do not exist in the class information table. 2. Change the values in the primary table and make the records in the relevant table independent.
The class number in the student information table should change accordingly. 3. delete a record from the primary table, but there are still records matching the record. If the class in the class information table is deleted
Level numbers cannot appear in the student information table. Generally, the reference Integrity Constraint is implemented through the reference relationship between the primary key and the foreign key.
Syntax for creating foreign key constraints: alter table sub-table add constraint name foreign key (sub-table foreign key) REFERENCES primary TABLE (primary KEY of the main TABLE );
Example: alter table student info TABLE
Add constraint fk _ child table name_foreign key foreign key (stu_cla_id)
REFERENCES class information table (cla_id );
Custom integrity constraints: constraints are usually imposed by Database Rules, stored procedures, or trigger objects.