Create Store Procedure to Count Number of records in Database for each table
Hello,
I have created the code which counts the number of records for each table in database. However, I want create store procedure for this code this code that when ever use execute the Store Procedure can provide the database name to execute it and as a result
table will display number of records in each table.
Below you will find the code its working:
CREATE
TABLE #TEMPCOUNT
(TABLENAME
NVARCHAR(128),
RECORD_COUNT BIGINT)
-- Creating a TEMP table
EXEC
sp_msforeachtable
'insert #tempcount select ''?'', count(*) from ? with (nolock)'
SELECT
* FROM
#TEMPCOUNT
ORDER
BY TABLENAME
DROP
TABLE #TEMPCOUNT
This code need to be convert in store procedure and user can give database name when execute the procedure in order to count the records.
Looking forward for your support.
Thanks.
SharePoint_Consultant_EMEA
Something like:
set quoted_identifier off
go
create procedure usp_TableCounts
@DBName as varchar(1000)
as
set nocount on
declare @SQLToExecute varchar(1000)
CREATE TABLE #TEMPCOUNT (TABLENAME NVARCHAR(128), RECORD_COUNT BIGINT) -- Creating a TEMP table
set @SQLToExecute = @DBName + ".dbo.sp_msforeachtable 'insert into #tempcount select ''?'', count(*) from ? with (nolock)'"
print @SQLToExecute
exec (@SQLToExecute)
SELECT * FROM #TEMPCOUNT
ORDER BY TABLENAME
DROP TABLE #TEMPCOUNT
GO
Satish Kartan www.sqlfood.com
Similar Messages
-
Count number of records in a internal table
hi
i want to count number of records in internal table
pls let me know how to count the number of records in a internal table.
regards
Arorahi
one way is
data field type i.
Decribe table itab lines field.
write: / field.
displays the no of records in tha internal table
or if u want to write logic.
data:
w_count type i.
loop at itab.
w_count = w_count + 1.
endloop.
write: / w_count.
displays the no of records.
reward points if useful. -
Counting number of records in a data block
hi folks,
Simple question for you guys: How can I count number of records in a data block.
In other words, say I have 10 detail records listed on a data block (one of my columns is a non-database item for entering a number). Now I just want to do somethin like:
Select count(*) From <data_block> into lnRecCount
Where <non-database column> <> 0 ;
Can I do this in a button trigger? I can't get it to work?
Thanks,
bobYou should make a routine that go through records of the block and count the records that agree with your condition.
-
To count number of records in an internal table for a condition
Hello All,
I want to count number of records in an internal table for a condition.
For e.g. -- I have one internal table IT which having fields F1, F2, F3, F4, F5.
Now, I want number of records in itnternal table IT where F1 = 'ABC'.
Is it possible to do..?? If yes, then how.??
Thanks in advance...!!
Regards,
Poonam.Hi,
If you mean an internal table, there are a few ways to do this.
1 One would be to loop over the table with a WHERE clause and increment a counter.
data: lv_counter type i.
clear lv_counter.
loop at itab where fld1 = 'ABC'.
lv_counter = lv_counter + 1.
endloop.
lv_counter now has the number of rows per the condiction.
2 Well, you may want to try this as well, and compare to the LOOP way. Not sure what kind of overhead you may get doing this way. Here ITAB is our main internal table, and ITAB_TMP is a copy of it. Again I think there may be some overhead in doing the copy. Next, delete out all records which are the reverse of your condition. Then whatever is left is the rows that you want to count. Then simply do a LINES operator on the internal table, passing the number of lines to LV_COUNT.
data: itab type table of ttab.
data: itab_tmp type table of ttab.
itab_tmp[] = itab[].
delete table itab_tmp where fld1 'ABC'.
lv_count = lines( itab_tmp ).
Thanks & Regards,
ShreeMohan -
How to create a procedure to send a mail if the Database is down?
Hi,
I have created the below procedure to send a mail if the count is less than 1300. It scheduled daily @ 15 30 hrs. Its fine.
CREATE OR REPLACE procedure SCOTT.hrsmail
is
v_count number;
begin
Select count(*) into v_count from emp;
if v_count < 1300
then
UTL_MAIL.send(sender => '[email protected]',
recipients => '[email protected]',
cc => '[email protected]',
bcc => '[email protected]',
subject => 'Testing the UTL_MAIL Package',
message => 'If you get this, UTL_MAIL package
else
null; --what you want to do here
end if ;
end;
Sometime the Database is down, so the job is not running.
How to create a procedure to send a mail if the database is down?
Pls help me. Its highly appreciated.
Thanks
Niharnihar wrote:
How to create a procedure to send a mail if the database is down?And what if the database is up, but the network down? Or the database up and mail server down? Or mail server undergoing maintenance?
There are loads of "+What if's+" - and in that respect, playing "+What if database is down..+" in this case does not make any sense. You do not use the database to monitor its own up/down status. You do not rely just on SMTP as notification protocol that the database is down.
The correct approach would be using something like SNMP as the monitoring protocol. A monitoring system that can process SNMP and perform some basic root cause analysis (e.g. network to the database server down, database server status unknown). And this system supporting notification methods like SMTP, SMS and so on. -
Total number of record in database??
Hi,
How to find total number of record in database using Single Query/Statement?
ThanksHere we go, in a Single Statement Block
SQL> ed
Wrote file afiedt.buf
1 DECLARE
2 v_cnt NUMBER := 0;
3 v_tot NUMBER := 0;
4 CURSOR cur_tables IS
5 SELECT table_name FROM user_tables;
6 BEGIN
7 DBMS_OUTPUT.ENABLE(1000000);
8 FOR t IN cur_tables
9 LOOP
10 EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM '||t.table_name INTO v_cnt;
11 v_tot := v_tot + v_cnt;
12 END LOOP;
13 DBMS_OUTPUT.PUT_LINE('Total Table Rows: '||v_tot);
14* END;
SQL> /
Total Table Rows: 5850553
PL/SQL procedure successfully completed.
SQL>What use it is is anybody's guess.
Note: This only works on the users own tables, not all the system tables or tables from other schemas in the database. -
Are there any ways to get sequence number other than getting it for each re
are there any ways to get sequence number other than getting it for each record
CACHE is the number of values Oracle stores in memory. So the first call to NEXTVAL Oracle grabs x numbers; subsequent calls to NEXTVAL are served from memory until they're all gone and them another bunch is grabbed. The attached sql*plus output demonstrates this behaviour.
Note that normally unused numbers in the cache are returned to the data dictionary but in exceptional circumstances (DB crash) they may be lost.
Cheers, APC
SQL> create sequence seq cache 3
2 /
Sequence created.
SQL> select last_number from user_sequences
2 where sequence_name = 'SEQ'
3 /
LAST_NUMBER
1
SQL> select seq.nextval from dual
2 /
NEXTVAL
1
SQL> select last_number from user_sequences
2 where sequence_name = 'SEQ'
3 /
LAST_NUMBER
4
SQL> select seq.nextval from dual
2 /
NEXTVAL
2
SQL> select last_number from user_sequences
2 where sequence_name = 'SEQ'
3 /
LAST_NUMBER
4
SQL> select seq.nextval from dual
2 /
NEXTVAL
3
SQL> select last_number from user_sequences
2 where sequence_name = 'SEQ'
3 /
LAST_NUMBER
4
SQL> select seq.nextval from dual
2 /
NEXTVAL
4
SQL> select last_number from user_sequences
2 where sequence_name = 'SEQ'
3 /
LAST_NUMBER
7
SQL> -
Increase the number of portions in process for each conversion object
I experts,
I configured SAP TDMS 3.0 with SP 14 to transfer test data from QAS to DEV (both is ECC 6.0) for the first test with TDMS TIM (Time Based Reduction).
The data transfer phase is still running (99% - 60hs running). We analyzed the Display Runtime Information report and see that objects of conversion with similar calc. records and calc. GBytes have very different the Net Runtime.
TMDS currently is working with four objects of conversion, processing a portion of each.
Conversion objects that are running are:
- Z_LTBP_002
- Z_TSEGE_002
- Z_VEVW_002
- Z_YST27_002
We check in the receiver system, and we see that is use only one DIA process to update the each table.
How can increase the performance of the update? Is correct that use only 1 DIA process for this??
Can I increase the number of portions in process for each conversion object?
Any help is greatly appreciated.
Regards,
SergioHi,
Check SAP Note 916763 - TDMS performance composite SAP note
Note 890797 - SAP TDMS - required and recommended system settings
Thanks
Sunny -
How to create xsd's for each table in repository instead of entire repos
Hi Gurus,
Is there any way i could create xsd's for each table in the repository separately instead of creating single xsd file from "Export repository schema" option which creates a single xml file for the entire repository.I need to create xsd for each table in repository...
Any Help greatly appreciated
Thanks
AravindOpen the Lookup table you want the XSD for, in Data manger
Export it to access.( You can select all the fields you want to export to access and then check option "open Access after export")
Now in Access, again right click the table and export it to XML.
Provided you have .NET frame work installed on the machine where you are doing this export, you can do the following:
Use XSD.exe from command prompt and get the XSD.
Use the following link as a reference for XSD stuff.
http://msdn.microsoft.com/en-us/library/x6c1kb0s(VS.71).aspx
(OR)
Get the whole XML of the repository and distill the whole structure for Lookups and create XSD using any standard XML editor. -
Count the no of irritation in for each loop
I want to count no of irritation in the for each loop container.
Thank you for the help.If I were using C#, I would do something like that:
First I would define another counter variable
int anotherCounter=0;
then, in for each loop I would parse your text by splitting from the pipe characters. If it matches the value I want, i simply increment the counter.
string[] strColumnArr = strLine.Split("|".ToCharArray());
if (strColumnArr.Length > 0)
if (strColumnArr[1] == "myValue") anotherCounter++;
smalkim - MCT, MCSD, MS, MCPS -
Hello,
I get but not the app. store in my dock.
App. store is not installed, how do I do it for each other?
I have my apple software update.
App.store app but after my update is not in the dock and system.
Kees.Hi Kees ...
Your profile indicates you are running Leopard v10.5.8
You need to upgrade to Snow Leopard V10.6 in order to use the App Store. This is an "upgrade", not an "update".
Make sure your Mac meets Snow Leopard's requirements here.
You must have the minimum of v10.6.6 installed in order to access the App Store.
You can purchase Snow Leopard here > Mac OS X 10.6 Snow Leopard - Apple Store -
Oracle Procedure returning more number of records
Hi,
I have created an Oracle Procedure which is supposed to fetch a record as per the input parameter passed.
The core query in the procedure is as below -
SELECT DISTINCT col1 FROM my_tab WHERE col2 = 'Input parameter'
Few of the input parms (col2) has more number of records (col1) and so the procedure gives an error like -
'ORA-01422: exact fetch returns more than requested number of rows'
Could you please let me know how can I modify the procedure so that it would return more number of records as the case may be?
Thank you!It still gives me the same error when it encounters more than one output.Yes, I'm sure it does.
But we can't tell you how to fix it because we don't know what you want.
What's the purpose of the procedure?
Is it to "spell check" the name of an intermediary? If so, you'll need to figure out what to do when you have more then one person with the same name.
You can add AND ROWNUM = 1. Or perhaps you can trap the too_many_rows exception.
Your procedure doesn't return anything (no out variables). Is that correct?
Or is the purpose of the procedure to return the ID of the matching name? -
BODS cannot create store procedure at DB2 at Unix
Hi,
I run BODS X3.1 and it can't create, drop store procedures at DB2 at unix. It recommends to authorize the user to do so. However, I have checked DB2 online doc, it mentioned need to set CREATE PROCEDURE authority. However, I can't find any command to do it.
Does anyone using DB2 that can provide help?
Thank you.I think I got found the bug. It is select from a regular table to load another regular table using Auto correct load method. If only normal loading, no create procedure sql is generated and no warning message.
For using Auto correct load method:
(1) first, it got to perform drop procedure as:
DROP PROCEDURE "BODSOWN".di1125368_1FOOTE; .
Note:
(a) I run this command at db2 and it contain syntax error, saying:
SQL0104N An unexpected token ";" was found following "WN".di1125368_1FOOTE".
(b) which mean the semicolon ; is not needed. If I delete this ; away, it can go through but still will complain the stored procedure "BODSOWN.di1125368_1FOOTE" doesn't exist. But that is another issue which is expected.
(2) secondly, It will generate a CREATE PROCEDURE as such:
CREATE PROCEDURE
"BODSOWN".di1125368_1FOOTE ( IN before_c1 VARCHAR (100) , IN after_c1 VARCHAR (1) , IN after_c2 VARCHAR (40) , IN after_c3
INTEGER , IN after_c4 VARCHAR (100) )
LANGUAGE SQL
BEGIN
DECLARE local_var INT DEFAULT 0;
SELECT COUNT(*) INTO local_var
FROM "BODSOWN"."FOOTER_RECORD"
WHERE "DI_FILENAME" = before_c1 ;
IF local_var = 0 THEN
INSERT INTO "BODSOWN"."FOOTER_RECORD" ("RECORD_TYPE", "SRCSYS_OR_COUNTER", "ROW_COUNTER", "DI_FILENAME")
VALUES (after_c1, after_c2, after_c3, after_c4 );
ELSE
UPDATE "BODSOWN"."FOOTER_RECORD"
SET "RECORD_TYPE" = after_c1 ,
"SRCSYS_OR_COUNTER" = after_c2 ,
"ROW_COUNTER" = after_c3 ,
WHERE "DI_FILENAME" = before_c1 ;
END IF;
END
Note:
(a) this create procedure contains syntax error, the line "ROW_COUNTER" = after_c3 , a comma shouldn't be inserted which afterward is the WHERE clause. Meaning is should be "ROW_COUNTER" = after_c3 without comma.
(b) if i run this create procedure at db2 without the comma error, it will be successful, if not if will give error saying:
SQL0104N An unexpected token ""DI_FILENAME"" was found following "" =
after_c3 , WHERE". -
How to create store procedure using cursor, and looping condition with exce
Hi,
I am new in pl/sql development , please help me for follwoing
1. I have select query by joining few tables which returns lets say 100 records.
2. I want to insert records into another table(lets say table name is tbl_sale).
3. If first record is inserted into tbl_sale,and for next record if value is same as first then update into tbl_sale else
insert new row
4. I want to achieve this using store procedure.
Please help me how to do looping,how to use cursor and all other necessary thing to achieve this.DECLARE
b NUMBER;
BEGIN
UPDATE tbl_sale
SET a = b
WHERE a = 1;
IF SQL%ROWCOUNT = 0
THEN
INSERT INTO tbl_sale
(a
VALUES (b
END IF;
END;note : handle exceptions where ever needed
Regards,
friend
Edited by: most wanted!!!! on Mar 18, 2013 12:06 AM -
How to count number of records for a field based on condition?
Hi guys,
I want to know how to find count of records coming from the database for a particular field based on some condition.
I need to use this count to suppress some headers. Because of this i am not able to use running totals. Is there any other way?
Ex scenario:
I have account number and currency fields, those are coming from database. And i need to count the number of accounts whose currency is not Euro.
Thanks in advance,
Vijay.A simple formula can do that:
//Formula begin
if {your account field}<>"Euro" then 1
//Formula end
This formula can be summarized. (by group or report)
Bryan Tsou@Taiwan
Maybe you are looking for
-
How do I manage 2 Ipads and 2 iphones on one ITunes account.
How do I manage 2 Ipads and 2 iphones on one ITunes account. Each device has a different name. But every time I plug them into iTunes on my Pc all the apps get screwed up. apps disappear etc. I have "sync apps" selected without automatic updates. I
-
How do you convert a date entry to a numeric value?
In Excel, I used to use the MAX() function on a range of dates to get the latest date from the range. This does not work in Numbers. Here is the function I used in Excel: =IF(OR(TODAY()-MAX(J4:J56)>179,'Sheet 1 - Table 1'!I2-MAX(I4:I56)>4999),"NEED
-
Plain text files appeared from nowhere in my finder window
I have a whole bunch of plain text files that have appeared in my finder window when searching in my user profile at the stage where I can view documents, desktop, music etc [sorry not sure what this is called and wanted to make obvious what I'm talk
-
If I'm working on aphoto in CS6, can I switch to Camera Raw without going thorugh Bridge?
-
Well... I have a strange one. I'm able to burn some playlists, but not others. I purchased and downloaded an album yesterday - attempted to burn. Error: 4701 Thought I'd try another playlist/album. No problem. Successful burn. Any thoughts? I've down