How to create a new schema / new user in Oracle Database 11g?

I applied for an internship at the company, and as a question I was asked to create a scheme for their company with certain requirements and send them a DDL file. I installed the Oracle 11g Express Edition database, but how do I create a new schema in the Oracle 11g database? I searched the net for a solution, but couldn't figure out what to do. And after creating the schema, which file should I send them by mail?

+76
sql database oracle11g database-design schema
Aug 23 '13 at 12:39 on
source share
5 answers

Generally speaking, the scheme in the oracle is the same as that of the user. Oracle Database automatically creates the schema when creating the user. A file with the .dll file extension is an SQL data definition file.

Create a new user (using SQL Plus)

Basic SQL Plus Commands:

- connect: connects to a database - disconnect: logs off but does not exit - exit: exists 

Open SQL Plus and write:

 / as sysdba 

sysdba is a role and is similar to "root" on unix or "Administrator" on Windows. He sees everything, can do everything. Internally, if you connect as sysdba, your schema name will be SYS.

Create a user:

 SQL> create user johny identified by 1234; 

View all users and see if johny is a user:

 SQL> select username from dba_users; 

If you try to log in as johny, you get an error:

 ERROR: ORA-01045: user JOHNY lacks CREATE SESSION privilege; logon denied 

A user must at least create a session privilege to log in, so we must grant the user these privileges:

 SQL> grant create session to johny; 

Now you can connect as johny user:

 username: johny password: 1234 

To get rid of the user, you can delete him:

 SQL> drop user johny; 



This was a basic example showing how to create a user. It can be trickier. Above, we created a user whose objects are stored in the default tablespace of the database. In order to have the database in order, we must put user objects in its own space (a table space is a distribution of space in a database that can contain schema objects).

Show table spaces already created:

 SQL> select tablespace_name from dba_tablespaces; 

Create tablespace:

 SQL> create tablespace johny_tabspace 2 datafile 'johny_tabspace.dat' 3 size 10M autoextend on; 

Creating a temporary table space (Temporaty temporary table space is a distribution of space in the database that can contain temporary data that is stored only during the entire session. This transient data cannot be restored after a process or instance crashes.):

 SQL> create temporary tablespace johny_tabspace_temp 2 tempfile 'johny_tabspace_temp.dat' 3 size 5M autoextend on; 

Create a user:

 SQL> create user johny 2 identified by 1234 3 default tablespace johny_tabspace 4 temporary tablespace johny_tabspace_temp; 

Provide some privileges:

 SQL> grant create session to johny; SQL> grant create table to johny; SQL> grant unlimited tablespace to johny; 

Log in as johny and check what privileges it has:

 SQL> select * from session_privs; PRIVILEGE ---------------------------------------- CREATE SESSION UNLIMITED TABLESPACE CREATE TABLE 

With the creation of a table privilege, a user can create tables:

 SQL> create table johny_table 2 ( 3 id int not null, 4 text varchar2(1000), 5 primary key (id) 6 ); 

Insert data:

 SQL> insert into johny_table (id, text) 2 values (1, 'This is some text.'); 

Choose:

 SQL> select * from johny_table; ID TEXT -------------------------- 1 This is some text. 

To get DDL data, you can use the DBMS_METADATA package, which "provides you with a way to retrieve metadata from a database dictionary as XML or create DDL and send XML to recreate the object." (using http://www.dba-oracle.com/oracle_tips_dbms_metadata.htm )

For the table:

 SQL> set pagesize 0 SQL> set long 90000 SQL> set feedback off SQL> set echo off SQL> SELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name) FROM USER_TABLES u; 

Result:

  CREATE TABLE "JOHNY"."JOHNY_TABLE" ( "ID" NUMBER(*,0) NOT NULL ENABLE, "TEXT" VARCHAR2(1000), PRIMARY KEY ("ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DE FAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "JOHNY_TABSPACE" ENABLE ) SEGMENT CREATION IMMEDIATE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DE FAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "JOHNY_TABSPACE" 

For the index:

 SQL> set pagesize 0 SQL> set long 90000 SQL> set feedback off SQL> set echo off SQL> SELECT DBMS_METADATA.GET_DDL('INDEX',u.index_name) FROM USER_INDEXES u; 

Result:

  CREATE UNIQUE INDEX "JOHNY"."SYS_C0013353" ON "JOHNY"."JOHNY_TABLE" ("ID") PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DE FAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "JOHNY_TABSPACE" 

Additional Information:

DDL

DBMS_METADATA

Schema Objects

Differences between schema and user

Rights

Create User / Schema

Create table space

SQL Plus Commands

+223
May 30 '14 at 13:33
source share

This is a working example:

 CREATE USER auto_exchange IDENTIFIED BY 123456; GRANT RESOURCE TO auto_exchange; GRANT CONNECT TO auto_exchange; GRANT CREATE VIEW TO auto_exchange; GRANT CREATE SESSION TO auto_exchange; GRANT UNLIMITED TABLESPACE TO auto_exchange; 
+15
Feb 17 '17 at 8:23
source share

Let you get started. Do you have any knowledge in Oracle?

First you need to understand what SCHEMA is. A schema is a collection of logical data structures or schema objects. The schema belongs to the database user and has the same name as this user. Each user owns one scheme. Schema objects can be created and processed using SQL.

  • CREATE USER acoder; - whenever you create a new user in Oracle, a schema is created with the same name as the user name, where all its objects are stored.
  • GRANT CREATES A SESSION IN acoder; β€œIf you do not, you cannot do anything.”

To access another user-defined schema, you must grant privileges to a specific object in that schema, or possibly assign the SYSDBA role.

That should get you started.

+14
Aug 23 '13 at 14:00
source share
 SQL> select Username from dba_users 2 ; USERNAME ------------------------------ SYS SYSTEM ANONYMOUS APEX_PUBLIC_USER FLOWS_FILES APEX_040000 OUTLN DIP ORACLE_OCM XS$NULL MDSYS USERNAME ------------------------------ CTXSYS DBSNMP XDB APPQOSSYS HR 16 rows selected. SQL> create user testdb identified by password; User created. SQL> select username from dba_users; USERNAME ------------------------------ TESTDB SYS SYSTEM ANONYMOUS APEX_PUBLIC_USER FLOWS_FILES APEX_040000 OUTLN DIP ORACLE_OCM XS$NULL USERNAME ------------------------------ MDSYS CTXSYS DBSNMP XDB APPQOSSYS HR 17 rows selected. SQL> grant create session to testdb; Grant succeeded. SQL> create tablespace testdb_tablespace 2 datafile 'testdb_tabspace.dat' 3 size 10M autoextend on; Tablespace created. SQL> create temporary tablespace testdb_tablespace_temp 2 tempfile 'testdb_tabspace_temp.dat' 3 size 5M autoextend on; Tablespace created. SQL> drop user testdb; User dropped. SQL> create user testdb 2 identified by password 3 default tablespace testdb_tablespace 4 temporary tablespace testdb_tablespace_temp; User created. SQL> grant create session to testdb; Grant succeeded. SQL> grant create table to testdb; Grant succeeded. SQL> grant unlimited tablespace to testdb; Grant succeeded. SQL> 
+4
Dec 07 '15 at 20:05
source share

From the oracle Sql developer, execute the following SQL table:

 create user lctest identified by lctest; grant dba to lctest; 

then right-click "Oracle connection" -> new connection, then do everything lctest from the connection name to the username password. Test connection should pass. After connecting you will see a diagram.

0
Aug 22 '19 at 20:54
source share



All Articles