Wednesday, August 11, 2021

SQL Query Examples

The ORDER BY clause last in the SELECT statement

 

select last_name, job_id, departmet_id, hire_date from emp order by hire_date;



Create the user SQL Statement


create user user_name

identified by password;


*********************************************************************************

User System Privileges:-

After a user is created, the DBA can grant specific system privileges to the user.


      grant privilege [privilege] to user [user_name/role,public--];


Typical User Privileges:-




Granting system Privileges:-

The DBA can grant specific system privileges to a user’s.


 grant create session, create table, create sequence, create view to user_name(demo);



*********************************************************************************

SQL statement, privileges for insert data in to the table on.


      alter user sony(user name)

          quota unlimited on users;


***********************************************************************************


Creating a Role:-

Role is a named group of related privileges that can be granted to users.

A user can have access to several roles, and several user can be assigned the role.

Role are typically created for a database application.

     

create table, create view to role_name;


Grant privileges to a role:-

    create table, create view to role_name;


Grant a role to users:-

 grant role_name to user_name;

grant select on scott.emp to user_name;


As a admin privileges at a one time.

        grant select, insert, update, reference, alter, index, delete

           on scott.emp to role_name;

****************************************************************************************************

Changing your password

 alter user_name

    identified by password;


§  Grant privileges to update specific columns to user and roles.

  grant update (department_name, locaton_id

    on departments to demo, manager;


§  Revok statement is removing privileges of role, user, database


 revoke select, insert on departments from demo; 


Drop the unused column:-

alter table emp     

drop unused column;;






Monday, July 12, 2021

MIS (Management Information System)

 

MIS (Management Information System)




















What is information system?















































































































Saturday, July 10, 2021

Backup and Recovery Concepts

 

Control file recovery 

 



As we can see above pic there is not available the control file, let’s try for recovery.

Now let’s try to connect with database ……

[oracle@localhost ~]$ sqlplus /as sysdba



As you can see above pic it’s appearing the ERROR .. ORA-00205 

Let’s try to resolve it.

First of all let’s see how to find out error by error number,



[oracle@localhost ~]$ oerr ora 00205

Now let’s check the alert file

[oracle@localhost ~]$ cat /etc/oratab



[oracle@localhost trace]$ ls –ltr

[oracle@localhost trace]$ tail -100f alert_prod.log





SQL> show parameter control

SQL>exit

[oracle@localhost ~]$ cd  /u01/app/oracle/oradata/prod/

[oracle@localhost prod]$ ls -l

[oracle@localhost ~]$ cd  /u01/app/oracle/fast_recovery_area/prod/

[oracle@localhost prod]$ ls -l

[oracle@localhost prod]$ cp control02.ctl   /u01/app/oracle/oradata/prod/control01.ctl



[oracle@localhost prod]$ cd /u01/app/oracle/oradata/prod/

[oracle@localhost prod]$ ls -ltr

SQL> alter database mount;

SQL> alter database open;

SQL> select open_mode from v$database;

SQL> select name from v$controlfile;





Friday, July 2, 2021

Database Creation on Oracle 11g

Database Creation:-

 

We will learn how to create the database 

[oracle@linux ~]$ cd /

 [oracle@linux /]$ ls

[oracle@linux /]$ cd disk1 

[oracle@linux /]$ mkdir prod 

[oracle@linux /]$ mkdir data redo control log arch diag fra

 [oracle@linux /]$ cd $ORACLE_HOME/dbs

[oracle@linux dbs /]$ ls -lrt


[oracle@linux dbs ]$ vi initprod.ora

 

db_name=prod

memory_target=500m

control_files= '/disk1/prod/control/control02.ctl'

diagnostic_dest= '/disk1/prod/diag'

compatible=11.2.0


Save it.

Now let’s create a SQL script.


[oracle@linux dbs]$ vi dbcreation.sql


create database prod

datafile '/disk1/prod/data/system.dbf' size 300m autoextend on

sysaux datafile '/disk1/prod/data/sysaux.dbf' size 300m autoextend on

default tablespace user_data datafile '/disk1/prod/data/user01.dbf' size 500m

undo tablespace undotbs datafile '/disk1/prod/data/undotbs.dbf' size 100m

logfile group 1 '/disk1/prod/redo/redo1.rdo' size 100m,

        group 2 '/disk1/prod/redo/redo2.rdo' size 100m;


Save and come out...


[oracle@linux dbs ]$ sqlplus / as sysdba


 



SQL> startup nomount

ORACLE instance started.


### You can see here total system global area ###


SQL> @/ /u01/app/oracle/product/11.2.0/dbs/dbcreation.sql


Database created.


Now let’s create other database like procedure function and other objects.

SQL>@$ORACLE_HOME/rdbms/admin/catalog.sql 

SQL>@$ORACLE_HOME/rdbms/admin/catproc.sql

 SQL> @$ORACLE_HOME/sqlplus/admin/pubbld.sql

SQL> shut immediate

[oracle@linux dbs]$ sqlplus / as sysdba

SQL> startup 


Now database has connected...