Select All Tables With Rowcount !!
Jul 27, 2001Folks !!
Can someone suggest a select statement for Display of all the tables in the Db with their Row Count ?
thanks
Girish
Folks !!
Can someone suggest a select statement for Display of all the tables in the Db with their Row Count ?
thanks
Girish
Is there a script someone knows of which could give me the rowcounts of all the tables in a database?
thanks a lot!
Can someone throw light on how to get the rowcount of a table that is stored in any system tables? I want to get tablename and rowcount for all user tables in a database in a query. Is there anyway other than count(*)?
Thanks
Vinnie
Hi,
I need to select first record from a table.
This can be comfortably achieved by usibg set rowcount 1.
I need to do this with out using rowcount.
This is urgent.
Thanks
Krishna
hi, how to retrieve row count from an insert statement in dynamic sql?
CREATE PROCEDURE [dbo].[procTest]
AS
BEGIN
SET NOCOUNT ON;
DECLARE @nsql NVARCHAR(MAX)
DECLARE @i INT
SET @nsql = 'select * into tbl_user_test from tbl_user;
select @i = @@rowcount;'
exec sp_executesql @nsql;
END
The code doesn't work..
declare @i int;
Exec procTest, N'@i int output',@i=@i output
select @i;
I have a table that contains 10 millions records. The following 2 statements, which one provide better performance? Frankly, i have no idea how to compare the execution plan...
Select Top 10000 * From Table
OR
Set rowcount 10000
Select * From Table
How to find rowcount and size(space used) for all tables in a db? Can any one give me the script please?
Thanks,
I have a vb.net application that executes a simple flat file to sql table dtsx package. I want to capture the rowcount to display back to the user to verify the number of rows that were inserted or updated to the table. I have a Row Count component placed between the flat file source(without errors) and the destination component. I have assigned a variable named RecordCount to the Row Count component. So far so good I hope : )
Now, I also use a variable to "feed" the package the flat file source. This works fine, but I cannot figure out how to retrieve the row count information and how to assign that to the variable RecordCount.
Also, if anyone has any insight on the way to work with the OnProgress method in SSIS I would appreciate that as well. In SQL 2000 using DTS I create a "PackageEventsSink" that I had found online, and it worked great for monitoring the progress of the DTS. Can't seem to figure out how to get it to work in SSIS.
Thanx,
Mike
I've created a Stored Procedure which performs a Select against my table, and displays the rows returned via these stmts -
@RowCount int Output
SELECT @rowcount = @@RowCount
This Works fine when Executed from SQL Server, but when trying to invoke the SP from my ASP page it complains that the SP expects parameter '@RowCount' which was not supplied.
I don't need to supply it when invoking the SP directly, why do I need to supply it from ASP?
I tried defining it as NULL within my SP, but can't seem to get it to accept both the NULL & Output parms.
And while I'm at it, how do I get my ASP page to display this @RowCount value?
Many Thanks.
In sql I perform the following
SELECT * FROM
xlsdci x LEFT OUTER JOIN fffenics f ON f.[derived deal code] = x.[manual dcd id]
which gives me a row count of 2709 rows
In SSIS I have a merge join component (left outer)
left input = xlsdci with a sort order of 1 ASC on [manual dcd id] (OLE DB source component)
right input = fffenics with a sort order of 1 ASC on [derived deal code] (OLE DB source component)
which when run in the IDE gives me a rowcount of only 2594 rows
Why is this so?
Also if I change the join to INNER in the merge join, the number of rows drops dramatically to only 802.
Fair enough, I hear you cry, maybe there are IDs in the 'xlsdci' table that are not in the 'fffenics' table. Ok. But the following SQL reveals that there are only 14 rows(IDs) in 'xlsdci' that are not in 'fffenics'
SELECT * FROM xlsdci
WHERE [manual dcd id] NOT IN (SELECT [derived deal code] FROM dbo.fffenics)
What is going on here?
I have a problem where my users complain that a select statement takes too long, at 90 seconds, to read 120 records out of a database.
The select statement reads from 9 tables three of which contain 1000000 records, the others contain between 100 and 250000 records.
I have checked that each column in the joins are indexed - they are (but some of them are clustered indexes, not unclustered).
I have run the SQL Profiler trace from the run of the query through the "Database Engine Tuning Advisor". That just suggested two statistics items which I added (no benefit) and two indexes for tables that are not involved at all in the query (I didn't add these).
I also ran the query through the Query window in SSMS with "Include Actual Execution Plan" enabled. This showed that all the execution time was being taken up by searches of the clustered indexes.
I have tried running the select with just three tables involved, and it completes fast. I added a fourth and it took 7 seconds. However there was no WHERE clause for the fourth table, so I got a cartesian product which might have explained the problem.
So my question is: Is it normal for such a type of read query to take 90 seconds to complete?
Is there anything I could do to speed it up.
Any other thoughts?
Thanks
Hello,
I hope someone can answer this, I'm not even sure where to start looking for documentation on this. The SQL query I'm referencing is included at the bottom of this post.
I have a query with 3 select statements joined together like tables. It works great, except for the fact that I need to declare a variable and make it a table within two of those 3. The example is below. You'll see that I have three select statements made into tables A, B, and C, and that table A has a variable @years, which is a table.
This works when I just run table A by itself, but when I execute the entire query, I get an error about the "declare" keyword, and then some other errors near the word "as" and the ")" character. These are some of those errors that I find pretty meaningless that just mean I've really thrown something off.
So, am I not allowed to declare a variable within these SELECT tables that I'm creating and joining?
Thanks in advance,
Andy
Select * from
(
declare @years table (years int);
insert into @years
select
CASE
WHEN month(getdate()) in (1) THEN year(getdate())-1
WHEN month(getdate()) in (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) THEN year(getdate())
END
select
u.fullname
, sum(tx.Dm_Time) LastMonthBillhours
, sum(tx.Dm_Time)/((select dm_billabledays from dm_billabledays where Dm_Month = Month(GetDate()))*8) lasmosbillingpercentage
from
Dm_TimeEntry tx
join
systemuserbase u
on
(tx.owninguser = u.systemuserid)
where
Month(tx.Dm_Date) = Month(getdate())-1
and
year(dm_date) = (select years from @years)
and tx.dm_billable = 1
group by u.fullname
) as A
left outer join
(select
u.FullName
, sum(tx.Dm_Time) Billhours
, ((sum(tx.Dm_Time))
/
((day(getdate()) * ((5.0)/(7.0))) * 8)) perc
from
Dm_TimeEntry tx
join
systemuserbase u
on
(tx.owninguser = u.systemuserid)
where
tx.Dm_Billable = '1'
and
month(tx.Dm_Date) = month(GetDate())
and
year(tx.Dm_Date) = year(GetDate())
group by u.fullname) as B
on
A.Fullname = B.Fullname
Left Outer Join
(
select
u.fullname
, sum(tx.Dm_Time) TwomosagoBillhours
, sum(tx.Dm_Time)/((select dm_billabledays from dm_billabledays where Dm_Month = Month(GetDate()))*8) twomosagobillingpercentage
from
Dm_TimeEntry tx
join
systemuserbase u
on
(tx.owninguser = u.systemuserid)
where
Month(tx.Dm_Date) = Month(getdate())-2
group by u.fullname
) as C
on
A.Fullname = C.Fullname
Can anybody help ?
I need to get a limited set of records from sorted record set. For example, I have a table called Contacts which contains about 2000 records and I need to show records from 11 to 20 in the sorted order.
In Oracle I could use this query.
SELECT name FROM
(SELECT name, ROWNUM rnum from Contacts order by Name)
WHERE rnum between 11 and 20
Is anything equivalent available in SQL Server ? My need is to show
records page by page ( as in google/yahoo search ) in my asp page.
Thanks
Subhash
Does anybody know how to get at the value set by a SET ROWCOUNT statement from within a Stored Procedure. e.g. If I executed the following:-
SET ROWCOUNT 50
EXEC Proc1
How could Proc1 find out that the User had done a SET ROWCOUNT 50.
Any ideas would be appreciated
Can @@rowcount be used with a regular select statement?
Thanks,
Ninel
Can someone send me the script that counts the rows of the table within
a database?
Thanks,
Dianne
Is Set RowCount @RowCountMore efficient than simply using TOP?Thanks for any input.
View 5 Replies View Relatedi'm trying to get total rows found by query that uses top clause...for example:select top 10 myTable.* from myTable where myTable.number > 200let's say there are 13 rows matching that condition, and by using@@rowcount my result would be: 10.is there any way to get total row count, without affecting the TOPclause??? i believe that the mysql equivalent would beSQL_CALC_FOUND_ROWS().tnx...
View 1 Replies View RelatedI'm writing an INSERT, UPDATE and DELETE trigger on table A that needs to insert rows into a table B.
When a user issues a "SET ROWCOUNT" command to limit the number of rows, then does an insert, update or delete, the trigger is being limited to that number.
It is important that the trigger NOT be limited to ANY specific number of records, but it is undesireable for me to just wipe out the current "SET ROWCOUNT" setting for the user without their knowledge.
How do I get and preserve the current "SET ROWCOUNT" value from within my trigger, so I can cancel the limitation and then re-implement the setting once my work is done? I cannot find any documentation specifying where the ROWCOUNT value is set (I initially thought maybe the SYSPROCESSES table, but that doesn't seem to be it).
Example:
set rowcount 1
update TABLEA set val=val+1
<the TABLEA trigger fires, trying to insert multiple rows into TABLEB but is limited to a single row>
Ideas?
Hi,
I am using ssis to import .csv files into sql server tables.
How do I get the count of the records imported?
Thanks
Hi,
want to get the number of rows i'm retrieving from a source. This count should be written as " No: of roes retrieved" + varname
I have used OleDbSource, RowCount,Script [ To write in a file ]. Rows is the package level variable name used in rowcount. when i do this way it always writes as 0 in the file.
[code in Script]
Dim sw As New StreamWriter("D:Vijay1.txt")
s = Variables.Rows
sw.WriteLine(s.ToString)
sw.close
[/Code]
Can anyone help on this
I have a data flow task which contains an XML Source, The XML Source puts data into two OLEDB Destination tasks. What i need to do is check that the number of rows inserted in to the two data bases . Can anyone suggest the easiest way as i need to check before i can commit the transactions. Any help would be most appriciated
Thanks
Hello. What's the correct way of declaring a condition that selects two tables,with the following condition? Here's my code, it does not work.
SelectCommand="SELECT * FROM [table_1, table_2] WHERE table_1_data IS NULL, table_2_data IS NULL"
table_1_data is from table_1.
table_2_data is from table_2.
Thanks.
Hi I will be thankful if any one help me with the queryI have 5 tables InventorySalesInvoiceMasterInventorySalesMasterInventorySalesInvoiceSalesDeliveryNodeIds with fields salesInvoiceId and salesDeliveryNoteIdInventorySalesReturnMasterInventorySalesInvoiceSalesReturnIds with fields salesInvoiceId and salesReturnIdI want to retrive datas from InventorySalesInvoiceMaster and the below query works fine but if salesReturnId is not present for a salesInvoice the qurey is not returning any value the query is select ISIM.salesInvoiceId,ICM.customerName,ISIM.salesInvoiceDate from InventorySalesInvoiceMaster ISIM,InventoryCustomerMaster ICM,InventorySalesMaster ISM,InventorySalesInvoiceSalesDeliveryNodeIds ISISDNID,InventorySalesInvoiceSalesReturnIds ISISRNID,InventorySalesReturnMaster ISRM where ISIM.customerId=ICM.customerId and ISM.salesId=ISISDNID.salesDeliveryNoteId and ISRM.salesReturnId=ISISRNID.salesReturnId and ISIM.salesInvoiceId=ISISRNID.salesInvoiceId and ISIM.salesInvoiceId=ISISDNID.salesInvoiceId and ISIM.salesinvoiceId=32Thanks in AdvanceAnu Palavila
View 3 Replies View RelatedHi, I've got a problem... Let's say I have 3 tables each with only one column and the following information:
TABLE_A
A
B
C
TABLE_B
X
TABLE_C
G
H
I want to make a select of the three tables to have the following result:
COLUMN_A, COLUMN_B, COLUMN_C
A, X, G
B, , H
C, ,
If I do the following select:
select isnull(a.column_a, '') as column_a,
isnull(b.column_b, '') as column_b,
isnull(c.column_c, '') as column_c
from
table_a a, table_b b, table_c c
I get all the possible combinations as a result.. any ideas?
I'm using this statement to get info from 2 tables:
select holiday_notes.*, lookup.lookup_desc as type_desc from holiday_notes left join lookup on holiday_notes.[type]=lookup.lookup_id
where holiday_id=@holiday_id and delete_date is null order by create_date desc
It uses a specific id (holiday_id) to get the notes for that id.
What I need is all records from holiday_notes table, then the type (from holiday_id table) and also the holiday_name from Holiday_Ref table (which uses the holiday_id from holiday_notes table).I guess it's another join on the holiday_ref table? right join?
I'm using MS SQL 2005 server with two tables:
table 1
-------
code code_description sub_category notes
SH Shirt (Made in USA) x 20
HA Hat (Factory) x 36
SH Shirt (Made in China) x 24
table 2
-------
code code_description retail
---- ---------------- ------
TR Trousers 15.00
SH Shirt 10.95
I wish to be able to SELECT from both tables where code is like %S% and give the result:
SH Shirt
SH Shirt (Made in USA) x 20
SH Shirt (Made in China) x 24
How can I do this please?
hi,
i have created tables and i want to use a store procedure to get information from almost all of the tables...
lets say i have 4 tables - students, teachers,subjects and presence in classes.
students includes - name+phone+addresas+id
teachers includes - name+phone+degree+address+id and so on..
subjects includes- name+code+hours and so on
presence includes- id_student+id_teacher+code_subject+date and so on
now i want to create a table with all the students name , tachers name , subjects name what are in the presence table.
how can i get all of that information ? is it possible to write in one select statement?
what is right way to do it in a store procedure?
thnaks in advanced
Hi, from what I can find, there isn't a way to get the number of rows returned from a SQLDataReader command. Is this correct? If so, is there a way around this? My SQLDataReader command is as follows:Dim commandInd As New System.Data.OleDb.OleDbDataAdapter(strQueryCombined, connInd)Dim commandSQL As New SqlCommand("GetAssetList2", connStringSQL)Dim resultDS As New Data.DataSet()'// Fill the dataset with valuescommandInd.Fill(resultDS)'// Get the XML values of the dataset to send to SQL server and run a new queryDim strXML As String = resultDS.GetXml()Dim xmlFileList As SqlParameterDim strContainsClause As SqlParameter'// Create and execute the search against SQL ServerconnStringSQL.Open()commandSQL.CommandType = Data.CommandType.StoredProcedurecommandSQL.Parameters.Add("@xmlFileList", Data.SqlDbType.VarChar, 1000).Value = strXMLcommandSQL.Parameters.Add("@strContainsClause", Data.SqlDbType.VarChar, 1000).Value = strContainsConstructDim sqlReaderSource As SqlDataReader = commandSQL.ExecuteReader()results.DataSource = sqlReaderSourceresults.DataBind()connStringSQL.Close()And the stored procedure is such:DROP PROC dbo.GetAssetList2;GOCREATE PROC dbo.GetAssetList2(@xmlFileList varchar(1000),@strContainsClause varchar(1000))ASBEGINSET NOCOUNT ONDECLARE @intDocHandle intEXEC sp_xml_preparedocument @intDocHandle OUTPUT, @xmlFileListSELECT DISTINCTAssetsMaster.AssetMasterUID,SupportedFiles.AssetPath,FROM AssetsMaster, OPENXML (@intDocHandle, '/NewDataSet/Table',2) WITH (FILENAME varchar(256)) AS x,SupportedFilesWHEREAssetsMaster.AssetFileName = x.FILENAMEAND AssetsMaster.Extension = SupportedFiles.Extension UNIONSELECT DISTINCTAssetsMaster.AssetMasterUID,SupportedFiles.AssetPath,FROM AssetsMaster, OPENXML (@intDocHandle, '/NewDataSet/Table',2) WITH (FILENAME varchar(256)) AS x,SupportedFilesWHEREAssetsMaster.AssetFileName <> x.FILENAMEAND CONTAINS ((Description, Keywords), @strContainsClause)AND AssetsMaster.Extension = SupportedFiles.ExtensionORDER BY AssetsMaster.Downloads DESCEXEC sp_xml_removedocument @intDocHandle ENDGOHow can I access the number of rows returned by this stored procedure?Thanks,James
View 3 Replies View RelatedHi guys, can anybody help to solve this problem.
set @count=0Insert into User_t (userid, counter) select userid, count+1 from resultset is not working
0/p: bhasker 1 bhanu 1 kishore 1
but o/p must be bhasker 1 bhanu 2 kishore 3
Hi all
whether using TOP clause in SELECT statement or [SET ROWCOUNT n] before SELECT statement, I want to know how SqlServer Behave?
whether Fetching data and then choosing n record of them or as soon as fetching n records , Sql Server Stops retrieving the rest of the data?
Thanks in advance.
Regards.
Hello again everyone.....
Ok here's my problem.... This is definetly the strangest problem Ive had yet in my coding career..... anyways here it is:
I have a stored procedure which keeps a total number of hits for specific pages:
Procedure CMRC_Hits_Pages_Temp_Update
@Transaction nvarchar(20),
@Hits int = NULL,
@Page nvarchar(50) = NULL
AS
IF @Transaction = 'Delete'
BEGIN
DELETE FROM CMRC_Hits_Pages_Temp
END
IF @Transaction = 'Add'
BEGIN
CREATE TABLE #TempTableUpdate
(
Hits int
)
INSERT INTO #TempTableUpdate
(
Hits
)
SELECT
Hits
FROM
CMRC_Hits_Pages_Details
WHERE
Page = @Page
SELECT
Hits
FROM
#TempTableUpdate
IF @@Rowcount > 0
BEGIN
UPDATE CMRC_Hits_Pages_Temp
SET
Hits = Hits + @Hits
WHERE
Page = @Page
END
IF @@Rowcount < 1
BEGIN
INSERT INTO CMRC_Hits_Pages_Temp
(
Hits,
Page
)
VALUES
(
@Hits,
@Page
)
END
END
I've written it so if there hasn't been an entry for @Page, make a new one..... And if there is an entry allready for @Page, add @Hits to Hits.
Here's the strange part. When I run it in Query Analyzer (so I know there isn't a problem with my pages code), it works fine when I send @Page a value of 'Default' (As in my default page). But when I put any other value (ei. 'ProductsList', ProductDetails', 'test', 'Defauls') it doesn't work. It creates a new record even if there was a record for that page allready. I've tried erasing everything from the table over and over to give it a fresh start and it still only works for 'Default.'
I've tried every length of string possible thinking it may be the length, same problem.
It makes no sense to me why specific letters could make any difference in what this procedure does. A string is a string, right? Why should one string be more recognizable than another? Again, the most confusing thing I've enountered yet in my coding career.
I seem to always run into problems and think "this makes no sense" and then come to figure "Ohhh.... thats whats wrong..." But this problem here is definetely the cream.... It makes NO sense.....
Thank you to whomever can solve this mystery..... (If it is much of one....)
Just incase the Table info is important:
I have two Columns: Hits, int (4) & Page, nvarchar (50)
-Alec
Hi,I am just starting sql and have a stored proc which does a simple select and should return 2 when no rows match the selection criteria . The problem is that it always returns 2, even where there are rows which match the selection criteria and when there are no rows.CREATE PROCEDURE dbo.SelectSomething @a INT, @b INTAS SET NOCOUNT ON SELECT a, b, c, d FROM dbo.SomeTable WITH (READUNCOMMITTED) WHERE a = @a AND b = @b IF @@ERROR<>0 RETURN 1 IF @@ROWCOUNT=0 RETURN 2 -- Always Returns 2RETURN 0GOThanks for any help.
View 2 Replies View Related