Monday, June 10, 2013
Grant Select Privilege on SELECT_CATALOG_ROLE to User
Select * from dba_data_files
you'll see error message as ORA-00942: table or view does not exist
To allow the user to select table from Oracle data dictionary, you have to grant SELECT_CATALOG_ROLE privilege the that users. Use the following statement while logging in as sysdba
sql> grand SELECT_CATALOG_ROLE to user_name;
Sunday, May 26, 2013
Monday, May 13, 2013
Retrieve Table Information in MS SQL Server
Select Count(*) from TableName
However, it would have been better if we can retrieve number of records from the table with other information related to that table. SQL Server provides this store procedure to accomplish this task
sp_spaceused 'Table_Name'
more detail inside this book
The statement above shall return result in the table format. This SQL statement only works with one table in the chosen database. If we want to loop through all tables in the database to display table information, we can perform this step.
- First, create the temporary table to store result from store procedure
- Second, run the store procedure
- Last, use the select statement to display the result
Use the below SQL statement to create the temporary table in SQL Server
CREATE TABLE #tableSize(
TAB_NAME NVARCHAR(128),
RowsNO VARCHAR(30),
sizereserved VARCHAR(30),
sizedata VARCHAR(30),
index_size VARCHAR(30),
unused VARCHAR(30) )
Then, execute the store procedure below
INSERT #tableSize EXEC sp_msForEachTable 'EXEC sp_spaceused ''?'''
After the the procedure finish running, simply run the select statement.
SELECT * FROM #tableSize order by TAB_NAME
Find more books related to MS SQL Server
Thursday, November 15, 2012
How to access table in different schema in Store Procedure
On one Oracle database, there are several users or schemas. Each schema contains tables. These table belong to each user. It is possible for a user to access table in other schema. For instant, if there are three users in Oracle database, such as USER1, USER2, and USER3.
In event that the USER3 needs to access the table which belongs to the USER2. SQL select statement is written as
Select Col1, Col2, Col3 from USER2.TableName
This statement works fine when the SQL statement is run in Toad or SQL-Plus. However, if the SQL statement above is put into the store procedure, it will not work. The store procedure will not compiled correctly.
To correct this problem, the USER2 has to grant select on table privilege the USER3. Follow the step below:
- Login to the Oracle database as USER2
- Run this statement Grant Select on USER2.TableName to USER3;
Friday, July 29, 2011
Rename DATA FILE for Oracle
- The table space has to be taken offline; use the following command ALTER TABLESPACE tablespace_name OFFLINE NORMAL;
- Then data file is rename using the operating system.
- After that the Oracle DBA renames the data file in SQL Plus enviroment. Supposed that the old data file name is 'USER1.DBF'. The new data file name is 'NEW_USER.DBF'. Following the step 2, issue this SQL comment ALTER TABLESPACE 'tablespace name' RENAME DATAFILE 'C:\USER1.DBF' to 'C:\NEW_USER.DBF'; This assumes that the data file is located in drive C
- After rename the data file is performed in the Oracle environment, mount the tablespace online again, using this command: ALTER TABLESPACE tablespace_name ONLINE;
Wednesday, June 8, 2011
How to undrop a table in Oracle
Hone your skill on the Oracle database with this book