Friday, January 20, 2012

Back to basics Part-2

First thing that you should do in database is create user for your self. To create user write sql as given below:

SQL> create user temp identified by oracle default tablespace users temporary tablespace temp;

User created.

Still you can not use this user to login into database.To login using this user, first you need to grant some privilege to this user. Privilege need to login into database is : create session.

SQL> grant create session to temp;
Grant succeeded.

Now you can login into database, to do this just execute

SQL> conn temp/oracle
Connected.

Try to create table using sql given in Part-1. You will get error :)

User is ready, but still he has no space allocated in database into which he can store table after creation and he has no permission to create table as well. In database, storage is in terms of Tablesapce (It is logical name, actual storage is in datafile!!). So you need to grant some quota of tablespace to user temp, execute following sql for this:

SQL> alter user temp quota 5m on users;
User altered.
Here users is tablespace name created by Oracle during installation.

Now space is allocated(5 mb only), please modify this number as you wish and as you need.

To assign create table permission to user temp, grant create table privilege to temp user, to accomplish this execute sql as mention below.

SQL> grant create table to temp;
Grant succeeded.

Woohoo!! now you can create table, so create it and play some sql on it.