October 2009 Archives

Useful SQL Queries

| No Comments

You might find the following queries quite handy for your day to day SQL operations:

1. Get the total number of records in a table:

SELECT COUNT(*) FROM TABLE_NAME;

SQL User queries in Oracle

| No Comments

Here are a few  useful user SQL code snippets in Oracle:

1. To create a user

CREATE USER username
IDENTIFIED BY password
DEFAULT TABLESPACE USERS
TEMPORARY TABLESPACE TEMP;

2. Grant user privileges:

GRANT CONNECT, RESOURCE, CREATE SESSION, CREATE VIEW TO username;


3. Grant all privileges:

GRANT all privileges TO username;

4. Delete a user or to delete a user and the associated user schema

drop user username cascade;

This SQL Snippet get a list of all the tables under a user:

select * from user_objects where object_type = 'TABLE';

This SQL Snippet will get you a list of all the sequences in a DB Schema for the user tables

select * from user_sequences


This SQL Snippet will get you a list of all the view in a DB Schema for the user tables

select * from user_views;

Happy Coding :)

Finding out the Oracle Version using SQL

| No Comments
If you ever have to find out the version of Oracle using SQL, use the following SQL command and it will spit out all the details.

SQL
 SELECT * FROM V$VERSION;

OUTPUT

BANNER                                                          
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production                          
CORE    10.2.0.1.0    Production                                        
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production         
NLSRTL Version 10.2.0.1.0 - Production
----------------------------------------------------------------

Happy Coding :)

About this Archive

This page is an archive of entries from October 2009 listed from newest to oldest.

September 2009 is the previous archive.

November 2010 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Categories