Oracle creates a series of operations such as user, table space, authorization, and table creation_database

root login

docker exec -it oracle /bin/bash 进入docker

su - oracle

Enter sqlplus /nolog

conn / as sysdba

 

 

1. Use scott to log in to oracle as sysdba

conn scott/tiger as sysdba;

2. Create user

create user cps_platform identified by cps_platform ;

create user cps_profit identified by cps_profit ;

create user BOSSDB identified by cps_risk ;

create user cps_platform identified by cps_platform DEFAULT tablespace ts_cps_platform;

3. Modify the user's password

alter user sys identified by chually_2020;

4. View the table space where the user is located

By default, after the user is created, the system will assign a table space to the user by default (users). We can use the following SQL statement to check the table space where all users are located.

select username,default_tablespace from dba_users;

5. Create a table space

 - the current database instance

      show parameter instance_name

 

- View table space

SELECT a.tablespace_name,a.file_name,a.bytes total,b.bytes used,Round(( b.bytes / a.bytes) * 100, 2)||'%' usedrate

FROM dba_data_files a

LEFT JOIN dba_free_space b ON a.file_id = b.file_id

ORDER BY usedrate desc;

 

Generally, in the case of development, the user's default table space is of course not used, so you need to create a table space at this time.

Note: After the datafile is the physical storage path of the table space, the suffix of the file name can be anything you want. The folder must be created first, the file will not be created (the report already exists).

create tablespace farm_space datafile 'E:\temp\oracle\tablespace\farm\farm_space.dbf' size 100M  AUTOEXTEND ON NEXT 200M;

alter database datafile '/ora/oradata/radius/undo.dbf' resize 1024m

ALTER DATABASE DATAFILE'c:\SmartDB01.ora' AUTOEXTEND ON;// Turn on automatic growth

ALTER DATABASE DATAFILE'c:\SmartDB01.ora' AUTOEXTEND ON NEXT 200M ;// Automatically increase by 200m each time

ALTER DATABASE DATAFILE'c:\SmartDB01.ora' AUTOEXTEND ON NEXT 200M MAXSIZE 1024M;// Automatically increase by 200m each time , the maximum data table does not exceed 1G

 

6. Assign the table space to the user

alter user farm default tablespace farm_space;

 

8. Assign permissions to users

A table space is assigned to the user, and the user cannot log in yet (no login permission), so the user needs to be assigned permissions

 

-Authorize the highest authority to the user

create user umpay identified by umpay2020;

grant create session,create table,create view,create sequence,unlimited tablespace to umpay ;

grant dba to umpay ;

 

9. Grant the viewing authority of all tables under user A to user B

Authorize the query, insert, update, and delete of table A under user A to user B

grant select,insert,update,delete,all on userA.tableA to userB

 

SELECT 'GRANT SELECT ON A.'||OBJECT_NAME||' TO B;'

FROM DBA_OBJECTS

WHERE OWNER='A' AND OBJECT_TYPE='TABLE';

--Example:

select 'GRANT SELECT ON xrapsys.'||object_name||' to farm;'

from dba_objects

where owner='farmer' and object_type='TABLE';

 

10. After assigning permissions to the user, log in with the farm user

conn farm/unis;

11. Query the permissions that the user has

select * from session_privs;

12. Delete users and their related objects

drop user farm cascade;

13. Delete the table space

drop tablespace farm_space;

14. Query all tables under the current user name

TEST is the user name, and the user name must be uppercase.

select * from all_tables where owner='FARMER';

 

15. Table field comment modification

comment on table table name is'table comment information';

comment on column table name. The field name is'the comment information of the field';

16. Table field value modification

Single field: UPDATE table name SET column name = new value WHERE column name = a value

Multiple fields: UPDATE Person SET Address ='Zhongshan 23', City ='Nanjing'

WHERE LastName = 'Wilson'

 

17. Add fields to existing tables

alter table table name add (field name field type, field name field type);

--Add multiple fields to the existing table

alter table ba_key_manager add (

create_time DATE default sysdate,

update_time DATE,

cancellation_time DATE,

status VARCHAR2(2) default 0

);

--add notes

comment on column farm_user.create_time

is'Created time';

comment on column farm_user.update_time

is'Update time';

comment on column farm_user.cancellation_time

is'Logout time';

comment on column farm_user.status

is'Data status (0, normal; 1, cancelled)';

 

18. Modify the type or length of the field:

Note: When there is data in this column, the length of the field cannot be reduced, only the length can be increased.

table table name? modify? (field name? (new) field type);

alter table ba_branch_office modify (address number(32)); alter

19. Modify the name of the field:

alter table table name rename column (old) field name to (new) field name;

alter table farm_user rename column address to new_address;

20. Delete a field:

Note: When deleting a field, make sure that there is no data in this field.

alter table table name drop column field name;

alter table farm_user drop column new_address;

 

 

————————————————

Copyright statement: This article is the original article of the CSDN blogger "cyj7696". It follows the CC 4.0 BY-SA copyright agreement. Please attach the original source link and this statement for reprinting.

Original link: https://blog.csdn.net/cyj7696/java/article/details/89395066

 

Guess you like

Origin blog.csdn.net/wangjz2008/article/details/114081535