Foreach table in each database?

Hi, 
(SQL 2008R2 - enterprise)
Looking for a way of calculating table cardinality for all databases in an instance.  Is there a way of adapting this code to run against all databases?
DECLARE @TableRowCounts TABLE ([TableName] VARCHAR(128), [RowCount] INT) ;
INSERT INTO @TableRowCounts ([TableName], [RowCount])
EXEC sp_MSforeachtable 'SELECT ''?'' [TableName], COUNT(*) [RowCount] FROM ?' ;
SELECT [TableName], [RowCount]
FROM @TableRowCounts
ORDER BY [TableName]
I'm looking to run this job on a Sunday so I can see the actual cardinality as the estimated is way out. 
Thanks 

Are you looking for the below?
DECLARE @TableRowCounts TABLE ([databaseNAme] Varchar(100),[TableName] VARCHAR(128), [RowCount] INT) ;
INSERT INTO @TableRowCounts ([databaseNAme],[TableName], [RowCount])
EXEC sp_MSforeachdb 'select ''?'' as database_name,o.name,max(i.rowcnt )
From sys.objects o
inner join sys.sysindexes i on o.object_id=i.id
where o.type=''U''
group by o.name' ;
Select * From @TableRowCounts
One more method:
DECLARE @TableRowCounts TABLE ([databaseNAme] Varchar(100),[TableName] VARCHAR(128), [RowCount] INT) ;
INSERT INTO @TableRowCounts ([databaseNAme],[TableName], [RowCount])
EXEC sp_MSforeachdb 'SELECT ''?'',OBJECT_NAME(object_id), SUM(row_count) AS rows
FROM sys.dm_db_partition_stats
WHERE index_id < 2
GROUP BY OBJECT_NAME(object_id)' ;
Select * From @TableRowCounts
For partitioned tables, you can use the below:
DECLARE @TableRowCounts TABLE ([databaseNAme] Varchar(100),[TableName] VARCHAR(128), [RowCount] INT) ;
INSERT INTO @TableRowCounts ([databaseNAme],[TableName], [RowCount])
EXEC sp_MSforeachdb 'SELECT ''?'',TBL.name, SUM(PART.rows) AS rows
FROM sys.tables TBL
INNER JOIN sys.partitions PART ON TBL.object_id = PART.object_id
INNER JOIN sys.indexes IDX ON PART.object_id = IDX.object_id
AND PART.index_id = IDX.index_id
WHERE IDX.index_id < 2
GROUP BY TBL.object_id, TBL.name;' ;
Select * From @TableRowCounts

Similar Messages

  • How to use sp_msforeachdb with sp_rename for changing two table names in each databases-

    I have around 990 databases on a single SQL server in which I want to rename two tables 'AuditEvent' and 'AuditPropertyEvent' to 'AuditEvent_Archive' and AuditPropertyEvent_Archive table.
    Then I want to transfer lastest 6 months of data from now newly rename archived tables to New created Auditevent tables (Which will have same structure as old),
    For doing it I tried Cursor and SP_msforeachdb as possible solutions but its not allowing me to execute 2 sp_rename statements with go inside a dynamic statement.
    Please suggest any possible solutions on how to rename the 2 tables in all databases using sp_msforeachdb or cursor in a single go.

    exec sp_msforeachdb '
    USE [?]
    IF EXISTS (SELECT 1 FROM ?.INFORMATION_SCHEMA.TABLES WHER TABLE_NAME = ''AuditEvent'')
    EXEC sp_rename ''AuditEvent'',''AuditEvent_Archive''
    IF EXISTS (SELECT 1 FROM ?.INFORMATION_SCHEMA.TABLES WHER TABLE_NAME = ''AuditPropertyEvent'')
    EXEC sp_rename ''AuditPropertyEvent'',''AuditPropertyEvent_Archive''
    SELECT *
    INTO AuditEvent
    FROM AuditEvent_Archive
    WHERE datecolumn>dateadd(month,-6,getdate())
    SELECT *
    INTO AuditPropertyEvent
    FROM AuditPropertyEvent_Archive
    WHERE datecolumn >dateadd(month,-6,getdate())
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Displaying the sizes of every table in a database

    Hello All,
    I need to get the table sizes for each and every table in a database.
    I would have checked it manually but there are many number of tables.
    I am using SQL Server 2008 R2.
    Thanks and Regards, Readers please vote for my posts if the questions i asked are helpful.

    Hi,
    Please make habit of searching net before posting or if you dont know how to write a query. A simple search would lead you to
    http://stackoverflow.com/questions/7892334/get-size-of-all-tables-in-database
    SELECT
    t.NAME AS TableName,
    s.Name AS SchemaName,
    p.rows AS RowCounts,
    SUM(a.total_pages) * 8 AS TotalSpaceKB,
    SUM(a.used_pages) * 8 AS UsedSpaceKB,
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
    FROM
    sys.tables t
    INNER JOIN
    sys.indexes i ON t.OBJECT_ID = i.object_id
    INNER JOIN
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
    INNER JOIN
    sys.allocation_units a ON p.partition_id = a.container_id
    LEFT OUTER JOIN
    sys.schemas s ON t.schema_id = s.schema_id
    WHERE
    t.NAME NOT LIKE 'dt%'
    AND t.is_ms_shipped = 0
    AND i.OBJECT_ID > 255
    GROUP BY
    t.Name, s.Name, p.Rows
    ORDER BY
    t.Name
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it.
    My TechNet Wiki Articles

  • How to create a view consisting of data from tables in2 different databases

    Using Oracle 10.2g
    I have 2 databases Gus and haggis on Comqdhb schema.
    glink indicates a databse link between Haggis and Gus
    In Gus there are tables student,subject,grade,school containing columns like upn...
    STUDENT
    upn
    academicYear
    SUBJECT
    subject
    GRADE
    examlevel
    grade
    SCHOOL
    sn
    In HAGGIS there are tables student,grade,teacher containing columns upn...desc below.
    STUDENT
    upn
    GRADE
    grade
    upn
    academicyear
    level
    Create view in your HAGGIS database which will join all of the exam grades together. You should have one view which will produce the following relation :
    examGrade(upn, subject, examlevel, sn, grade,academicYear)
    so I need to create a view which gets the data from both the tables in both the databases.
    create view as examGrade(upn, subject, examlevel, sn, grade,academicYear) as select s.upn
    But i am not getting how to select a column from 2 tables in different databases
    I mean if i said
    select upn from comqdhb.student@glink,comqdhb.student;
    select upn from comqdhb.student@glink,comqdhb.student
    ERROR at line 1:
    ORA-00918: column ambiguously defined
    help me out,Thank you.

    Thank you for the reply will follow up the code format
    Create views in your HAGGIS schema database which will join all of the exam grades together. You should have one view which will produce the following relation :
    examGrade(upn, subject, examlevel, sn, grade,academicYear)
    I understand that there wont be duplication when we use conditions
    If i query
    select count(upn)
    from   comqdhb.student@glink I get 9000
    but after the union
    create view examGrade(upn, subject, examlevel, sn, grade,academicYear)
    as
    select distinct s.upn as upn
    ,                  g.subject as subject
    ,                  g."LEVEL" as examlevel
    ,                  g.grade as grades
    ,                  '9364097'
    ,                  to_number(g.academicyear) as academicyear
    from             comqdhb.student s
    ,                   comqdhb.grade g
    where           s.upn=g.upn
    union
    select            s.upn
    ,                   sb.subject
    ,                   g.elevel
    ,                   g.grade
    ,                   s.acyr
    ,                   sc.sn
    from              comqdhb.subject@glink sb
    ,                   comqdhb.student@glink s
    ,                    comqdhb.gradevalues@glink g
    ,                    comqdhb.school@glink sc,
    ,                    comqdhb.studentingroup@glink sg
    ,                    comqdhb.teachinggroup@glink tg
    where            sb.sid=tg.sid
    and                tg.gid=sg.gid
    and                sg.upn=s.upn
    and                g."LEVEL"=tg.elevel
    and                s.school=sc.id
    and                sc.id=tg.id; returns
    count(upn) from exam gradeIt gets stuck actually sometimes it returns
    932002 some results.
    2:
    Another problem i am having which i am trying to solve and written up my ideas but haven't been getting the expected results.Hope you can help.Thank you.
    Information:
    =======
    All children take exams at the age of 16 called a General Certificate of SecondaryEducation (GCSE).
    They have to study and take exams in Mathematics, English and Science, and can take other subjects such as History, French, Art etc. Most students will study between 5 and 10 different subjects before taking their GCSEs.
    For each exam, a student is awarded a grade from A*, A, B,C,D,E,F,G,U,X An A* grade is the best grade achievable and an X is the worst grade.
    In order to analyze how students have performed, each grade is mapped to a numeric value as follows:
    Grade Numerical score
    A* 8
    A 7
    B 6
    C 5
    D 4
    E 3
    F 2
    G 1
    U 0
    X 0
    Now why i need this avgGCSE is because i have to create a view containing avgGCSE of the students it is used in the next question where a condition is avgGCSE is between 6.5 and 7
    In order to calculate the avgGCSE the idea is to calculate the grades of the students and map the grades to their corresponding scores/values
    add them all up and div by the total no of grades to get the avg.
    desc comqdhb.STUDENT@glink;
    STUDENT
    =======
    UPN
    FNAME
    CNAME
    DOB
    GENDER
    PREVIOUSSCHOOL
    XGCSE
    SCHOOL
    ACYR
    STUDENTINGROUP
    =============
    UPN
    GID
    STARTDATE
    ENDDATE
    GRADE
    GRADEVALUES
    ===========
    GRADE
    LEVEL
    VALUE
    I have a opinion that xgcse in STUDENT table refers to the avgGCSE which i want to calculate as when i asked my professor as to what xgcse he said that he forgot to take it out of the table and it is not necessary while creating avggcse.
    select *
    from comqdhb.student@glink
    where xgcse<6.5; Displaying a result
    returns:
    UPN FAMILYNAME COMMONNAME DATEOFBIR GENDER PREVIOUSSCHOOL XGCSE SCHOOL ACYR
    ===========================================================================
    1011 KIMBERLY ABBOT 07-JUL-79 f none 3.93500948 2 2
    select *
    from comqdhb.student@glink
    where xgcse between 6.5 and 7 and upn = 1386; Displaying a result
    returns:
    UPN FAMILYNAME COMMONNAME DATEOFBIR GENDER PREVIOUSSCHOOL XGCSE SCHOOL ACYR
    ===========================================================================
    1386 STEPHANIE AANNESSON 15-JAN-79 f none 6.88873 2 2 so if xgcse is the avgGCSE then upn 1011 has avggcse<6.5 and 1386 has avggcse >6.5
    my idea was backward strategy like so now if we find out upn 1368 has suppose xgcse(avggcse)>6.5 how to extract the avggcse for the particular upn We need to map grades from GRADEVALUES to grade in STUDENTINGROUP and map upn from studentingroup to upn in student to output the values for the corresponding grades from GRADEVALUES
    select grade
    from comqdhb.studentingroup@glink
    where upn = 1011;
    Result:
    GRADE
    =====
    D
    F
    B
    E
    C
    E
    E
    B
    8 rows selected. Mapping each grade to the corresponding value and calculating we get
    32/8=4 total(values to corresponding grades)/no of grades.
    But the xgcse for upn 1011 is 3.935 and i am getting 4!! maybe xgcse isn't avggrade but ? is the procedure by me correct for calculating avggcse
    select grade
    from comqdhb.studentingroup@glink
    where upn = 1386;
    Result:
    GRADE
    ======
    A*
    A*
    A*
    A*
    B
    A*
    A*
    A
    B
    B
    B
    11 rows selected. grade to the corresponding value and calculating we get
    79/11=7.12 total(values to corresponding grades)/no of grades.
    But the xgcse for upn 1011 is 6.88... and i am getting 7.12!!
    But another problem
    when i say
    select   g.value,g.grade
    from     comqdhb.gradevalues@glink g
    ,        comqdhb.studentingroup@glink sg
    where    g.grade=sg.grade
    and      sg.upn=1011;
    result:
    ======
    VALUE GRADE
    ===========
      100 B
      100 B
       80 C
       60 D
       40 E
       40 E
       40 E
       20 F
        6 B
        6 B
        5 C
    VALUE GRADE
    =============
        4 D
        3 E
        3 E
        3 E
        2 F
    16 rows selected.
    select   distinct g.value,g.grade
    from     comqdhb.gradevalues@glink g
    ,        comqdhb.studentingroup@glink sg
    where    g.grade=sg.grade
    and      sg.upn=1011;
    result:
    ======
    VALUE GRADE
    ============
         2 F
       100 B
         6 B
         3 E
        60 D
         5 C
         4 D
        80 C
        40 E
        20 F
    10 rows selected. I am getting only 8 for the query
    select grade
    from comqdhb.studentingroup@glink
    where upn = 1386; here its becomming 10 and also its displaying values as 100 and ...
    select distinct *
    from   comqdhb.gradevalues@glink;
    GRADEVALUES
    ===========
    LEVEL      GRADE           VALUE
    ================================
    a          A                 120
    a          B                 100
    a          C                  80
    a          D                  60
    a          E                  40
    a          F                  20
    a          U                   0
    a          X                   0
    g          A                   7
    g          A*                  8
    g          B                   6
    LEVEL      GRADE           VALUE
    ================================
    g          C                   5
    g          D                   4
    g          E                   3
    g          F                   2
    g          G                   1
    g          U                   0
    g          X                   0
    18 rows selected. I was hoping if i could map the grades and get the values and calculate avggrade by total(values)/count(values)that would be it but here there are values like 100...
    select  sum(g.value)/count(g.grade) as avggrade
    from    comqdhb.gradevalues@glink g
    ,         comqdhb.studentingroup@glink sg
    where  g.grade=sg.grade
    and     sg.upn=1386;
    avggrade
    ========
    37.4375 the avggrade cant be this big and when i map each grade i obtained for 1368 like a to 7+b to 6 so on i get avggrade 7.12
    kindly help.
    Edited by: Trooper on Dec 15, 2008 4:49 AM

  • Unable to pull data from 2 tables of a database linked to a 2nd database

    I have a Crystal V7 Report I'm upgrading to Crystal 10 or 11.  It uses the following formula that works (data is in ONE MS Access database containing all three tables):
    If {PayrollCalc.qSource}=0  then {AuthorizedWithholding.qDesc
    else If {PayrollCalc.qSource}=1 or {PayrollCalc.qSource}= 2 then {UnionBenefitDetail.qUBDesc}
    else
    If {PayrollCalc.qSource}=4 then "Extra Tax" + {PayrollCalc.qID} else
    If {PayrollCalc.qSource}=5 then "Payroll Insurance" else
    If {PayrollCalc.qSource}=6 then {PayrollCalc.qID} else
    Mid ({PayrollCalc.qID},2 )
    The upgraded application software uses TWO SQL 2005 Express databases, replacing the one Access database.  PayrollCalc is a table in database A while UnionBenefitDetail & AuthorizedWithholding are tables in database B.  The links are left outer joined from PayrollCalc table to each of the others (I've tried all the enforcement options) but the formula no longer works.  If I remark out the part of the formula from one or the other of the "extra" tables, then the one still active works great but I can't get both to work in the same subreport.  There's no error, I just get a blank returned for the formula.  I'm not familiar with using the Add Command so I haven't tried that.  Can anyone help me?

    I confirmed that the join fields are identical:
    PRCalc Table - qConNo=int (32 bit), length 4
    PRCalc Table - qID=varchar (byte), length 10
    PRCalc Table - qSeg=int (32 bit), length 4
    UnionBenefit Table - qUBID=varchar (byte), length 10
    UnionBenefit Table - qUBSeg=int (32 bit), length 4
    Both of these UnionBenefit fields are left outer joined FROM the PRCalc Table's qID & qSeg fields
    Authorized Withholding - qConNo=int (32 bit), length 4
    Authorized Withholding - qSeg=int (32 bit), length 4
    These two fields are left outer joined FROM PRCalc's qConNo & qSeg fields.
    The qDesc & qUBDesc fields that I'm trying to print in the same subreport using the formula that's not working are both varchar (bye), length 50 fields.
    I have tried various other joins unsuccessfully.  I'm convinced that the left outer join is the correct one to use since neither of the tables from Database B will always have records that match up with those in Database A (PayrollCalc's database).  So yes, it appears that the left outer join does not work properly across two databases when more than one table in the 2nd database is used.  It works fine if I just use one table from database B & do a separate subreport for the other table.

  • Is there a way to create "temporary" tables in SAP database?

    Hello,
    Is there a way to create temporary tables in ABAP?
    Here is our scenario:
    1. Invoke a custom RFC that creates a temporary table and returns the name of the table.
    2. Invoke another custom RFC and pass this table name as parameter. This RFC internally does some INNER JOIN with the temporary table.
    3. Invoke the third RFC to delete the temporary table.
    Note that the name of the table cannot be static. We have many users using our application simultaneously and connecting to the SAP server.
    I would appreciate it if you could point me in the right direction.
    Thank you in advance for your help.
    Peter

    I just ran into a similar issue.  While only calling the select statement 2 times, each time had so many entries in the 'for all entries' list, that the compiler converted this into about 700 calls to the select.  Now since the select joined three real tables on the database, the trace shows this one select as being the slowest item in this application.
    I think that happened because 'for all entries' gets converted to an 'IN' clause, and then the total number of characters in any SQL statement has an upper limit.   So the compiler must make the select statement over and over until it covers all entries in the 'for all entries' list.  Is that correct?
    Since every database I ever saw has the concept of db temporary tables, I have used db temp tables many times for this sort of thing.
    The ABAP compiler could determine that more than one IN statement will be need, then use an alternate: write all the FOR ALL ENTRIES to a db temp table, then join on the db temp table, then drop db temp table.  Since the compiler does this sort of thing, no application code needs change to get the speed boost.

  • Error connecting to a table in a database

    I am trying to insert user login script and have an error.
    Can anyone tell me why Dreamweaver MX 2004 cannot connect to
    the tables in my databases? I am using MS Access 2002 and there are
    tables in the databses.
    I can supply a jpeg of the error if needed

    Hello,
    Are you using Windows XP SP2?
    If so, it's a known issue.
    Here's the fix:
    http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_19515&sliceId=2
    Click on "connectivity fails with local ASP.NET and ASP
    servers..."
    There's a link to download the extension fix in "Workaround"
    ASP: When using a local ASP test server running on XP SP2
    with Dreamweaver
    (i.e. the Testing Server URL prefix is set to "
    http://localhost"), and you
    specify "Using driver on testing server" or "Using DSN on
    testing server,"
    database connectivity fails. If you click the Test button in
    the Custom
    Connection String or Data Source Name (DSN) dialog box, it
    says the
    connection was made successfully. However, if you then try to
    browse the
    tables in the Databases panel or create a recordset, the
    database tables do
    not display or you get the following error message: "Unable
    to retrieve
    tables from this connection, click on the 'Define...' button
    to test this
    connection."
    Workaround: Download and install the Dreamweaver extension
    fix by Macromedia
    that resolves this issue (Ref. 179021). To use this
    extension, follow the
    steps below. The steps below apply to both ASP.NET and ASP
    sites:
    1.. In Dreamweaver, go to the Files panel and choose one of
    your ASP.NET
    site definitions.
    2.. Select Site > Advanced > Remove Connection
    Scripts.
    Note: If this option is grayed out, open an ASP.NET page in
    Dreamweaver.
    Removing the connection scripts will delete the contents of
    the
    _mmServerScripts folder, which is located in the testing
    server folder. The
    _mmServerScripts folder is hidden in Dreamweaver's Files
    panel, but will be
    visible if viewed with a different file browser. The
    _mmServerScripts folder
    consists of these three files: adojavas.inc, MMHTTPDB.asp and
    MMHTTPDB.js.
    The connection scripts are used by Dreamweaver to perform
    remote database
    connectivity when developing pages within Dreamweaver. These
    script files
    have no affect on your web pages during run-time (i.e. when a
    visitor views
    your ASP.NET pages via a web browser).
    3.. Repeat steps 1-2 for each of your ASP.NET site
    definitions.
    4.. Quit Dreamweaver.
    5.. Install the extension.
    6.. Restart Dreamweaver.
    7.. Go into the Files panel, select one of your ASP.NET
    sites, and open an
    .aspx file.
    8.. Go into the Databases panel and delete your existing
    database
    connections. Before deleting them, make sure to open up each
    connection and
    write down the settings. You can open a connection by either
    double-clicking
    the connection name, or right-clicking the connection name
    and selecting
    Edit.
    9.. Create a new database connection. Use the same
    connection names you
    had before, so any existing pages with DataSets and Server
    Behaviors still
    work correctly.
    10.. Click the Test button in the database connection dialog
    box. This
    will upload the new connection scripts to the testing server.
    11.. Repeat steps 7-10 for each of your Dreamweaver ASP.NET
    site
    definitions.
    Note: This extension is compatible with Dreamweaver MX 2004
    and Dreamweaver
    MX. The current version of the extension is 1.0.2. Version
    1.0.1 resolved a
    database connectivity problem with the ASP VBScript server
    model. Version
    1.0.2 includes the fixes in version 1.0.1 and also resolves
    compatibility
    issues with Dreamweaver MX (version 6). You can see which
    version of the
    extension you have by opening the Extension Manager.
    "ducati1" <[email protected]> wrote in
    message
    news:[email protected]...
    >I am trying to insert user login script and have an
    error.
    > Can anyone tell me why Dreamweaver MX 2004 cannot
    connect to the tables in
    > my
    > databases? I am using MS Access 2002 and there are
    tables in the databses.
    > I can supply a jpeg of the error if needed
    >
    >

  • Importing CSV files into Multiple Tables in One Database

     I have a web based solution using Microsoft SharePoint and SQL Server that is created to centralize dat collection and reporting of program metrics used in montly reviews.
    A person from each program enters dat manual or by pushing the data using automated data import tools. The user then is able to generate reports and provide presentations to their stakeholders.
    There are are programs that are located in US and 2 that are located in Japan. All, including programs in Japan use the MS Project with a plug-in tool that allows them to auto input data. When the user click the "Send To.." button, the data goes
    in to multiple tables in one database.
    Everything is set up exactly the same for every program; however, we have discovered becase of a firewall, along with some of the different settings that the MS Project has over in Japan, the 2 program users are not able to auto import their data.
    The suggestion is to have the program users export the MS Project file into a CSV and email it. I will then take it and convert the data, such as the dates and place them on a Network Drive. There will be 2 folders, one for each program.
    I feel it will be an easy process just to load the data from the Network Drive into the same tables that are created for auto import.
    My Concerns/Questions:
    1. Should I create 1 SSIS package or should there be 2, one for each program?
    2. US and Japan program users send their data once a month. The converted files are going to be saved in the location marked with a date (ex:201402). How can i have it to where SSIS will automatically load the data every time i place new files in the designated
    folders or when i update an exsisting file?
    Can you provide an example with your suggestion please?
    I greatly appreciate the assistance!
    Y_Tyler

    Hello Vikash,
    Thank you! This will help me get started.
    There will be 2 folders, one with files with Program A data and the other with files with Program B data. All will have the same fields, just coming from different programs. You stated that I will be able to to load both in one package. Would there be two
    paths since there will be two separate folders?
    Using the example you provided, i am confident that I can create the package using one path into one table but not sure how to get the files from 2 paths (if there is) into multiple tables.
    Can you help clarify this for me?
    Thank you!
    Y_Tyler

  • How can i find statistics tables in my database?

    code{
    Upgrade Statistics Tables Created by the DBMS_STATS Package
    If you created statistics tables using the DBMS_STATS.CREATE_STAT_TABLE procedure, then upgrade these tables by executing the following procedure:
    EXECUTE DBMS_STATS.UPGRADE_STAT_TABLE('SYS','dictstattab');
    In the example, 'SYS' is the owner of the statistics table and 'dictstattab' is the name of the statistics table. Execute this procedure for each statistics table.
    the above is one of the post upgrade step for 11gR2. How can i find statistics tables in my database?

    You need to read the complete context of this manual upgrade step:
    Step 33
    Upgrade Statistics Tables Created by the DBMS_STATS Package
    If you created statistics tables using the DBMS_STATS.CREATE_STAT_TABLE procedure, then upgrade these tables by executing the following procedure:
    EXECUTE DBMS_STATS.UPGRADE_STAT_TABLE('SYS','dictstattab');
    In the example, 'SYS' is the owner of the statistics table and 'dictstattab' is the name of the statistics table. Execute this procedure for each statistics table.You need to do this step for any statistics table that you created manually with DBMS_STATS.CREATE_STAT_TABLE.
    Marcus

  • Connection with tables of same database

    i want to access two tables of same database using JDBC.
    how can i do it in MS Access
    i have to create two connection one for each or two statement for same connection

    i want to access two tables of same database using
    JDBC.
    how can i do it in MS Access
    i have to create two connection one for each or two
    Yo don't need to create two connections to access two tables.
    Single Database connection is enough.
    Try the following pseudo code to access two tables
    1. get Database Connection
    2. create statement with query that is for table 1
    3.execute it and close the statement .
    4. again create the statement with query that is for table 2
    5. execute it and close the statement .
    6. close the connection.
    hope it will clear you,
    nvseenu
    statement for same connection,

  • How do I run sp_spaceused for all tables in a database?

    Hi,
    I am struggling to understand how to run the sp_spaceused sproc for all tables in a database.
    I know how to use it for one table but how would I replicate it automatically for each table in a given database?
    Regards,
    Ian.

    I just managed to alter the code of VidyaSagar and have pulled out all the information including Schema name. Below is what it looks like:
    set
    nocount
    on
    select
    'Database Name: ',
    db_name
    if
    exists(select
    name from tempdb..sysobjects
    where name='##tmp'
    drop
    table ##tmp
    create
    table ##tmp(TABLE_SCHEMA
    nvarchar(256),TABLE_NAME
    nvarchar(256),
    num_rows int,
    reserved_KB varchar(15),data_KB
    varchar(15),index_KB
    varchar(15),unsed_KB
    varchar(15
    go
    declare
    @tbl_schema nvarchar(256
    declare
    @tbl_name nvarchar(256
    declare
    @schema_tbl_name nvarchar(256
    declare
    tblname CURSOR
    for
    select
    TABLE_SCHEMA
    TABLE_NAME
    from
    INFORMATION_SCHEMA.TABLES
    where TABLE_TYPE='BASE
    TABLE' 
    open
    tblname
    Fetch
    next
    from tblname
    INTO @tbl_schema,@tbl_name
    WHILE
    @@FETCH_STATUS
    = 0
    BEGIN
    set @schema_tbl_name=@tbl_schema+'.'+@tbl_name
    insert
    into ##tmp(TABLE_NAME
    , num_rows
    , reserved_KB
    ,data_KB
    ,index_KB
    ,unsed_KB
    exec
    sp_spaceused
    @schema_tbl_name
    update ##tmp
    set TABLE_SCHEMA
    =@tbl_schema
    where TABLE_SCHEMA
    is
    NULL
    and TABLE_NAME=@tbl_name
    FETCH
    NEXT
    FROM tblname
    INTO @tbl_schema,@tbl_name 
    END
    CLOSE
    tblname
    deallocate
    tblname
    go
    select
    from
    ##tmp
    drop
    table ##tmp
    Warm Regards, Ajay

  • No tables found in database

    Last night I had a number of apps to udate (mainly CS6), so I set the 'update all' running and went to bed. I got up this morning to find all had updated fine as expected. However, since this morning I am consistely getting an error telling me that I have no tables in my database and can't therefore create recordsets etc...
    I didn't look to see if DWCS6 was one of the apps that required an update, but I can't seem to get it to always load the database tables when try to I create a recordset. It's very hit and miss, but unfortunately more miss at the mo'.
    Is anyone else experiencing this? I'm wondering if the update has broken something!

    When it losses connection, I am unable to connect to the DB regardless of whether I am testing the connection, creating a new recordset, copying recordsets that are months old, or using the bindings panel to drag a binding onto the page. When it looses connection, I get a http error in the recordset in the bindings panel.
    Everything was fine prior to the update, and nothing has changed apart from the update to the CS6/CC software.
    I can launch DW and have it work prefectly with any DB in any site, and then for no reason, it looses the connection. The connection will not work again until I quit DW and restart it. Outside of DW, I can see all databases, and I can see the contents of each. I am able to interact with MySQL databases create new tables and records, update them and delete them, but DW still won't connect until I restart it.
    As this has only started happening imediately after I updated the software, it would indicate a bug to me... and I have been reporting numerous bugs for DWCS6 with Adobe engineers.

  • What is te best way to copy a table from a database to another?

    Hello friends:
    I have two databases: an Access database and an Oracle database. I must copy the data from al tables from the Access database to the oracle database. The tables in the both databases are equal (number of columns, type, etc).
    I read an resultset from acces (select * from table1) and I insert every row in the Oracle database with an while loop (while (r.next)...). It works fine when there are a few rows, but I have a table with over 200000 rows, and when I'm copying the row number 30.000, the system goes very slow...
    How can I copy tables from a database to another more quickly?
    Thanks!

    CASE #1
    The most efficient method would be to copy all the rows from Microsoft Access and write them to a text file using Access's native interface (not JDBC), then use Oracle's SQL Loader utility (not JDBC) to insert the data.
    You can insert 200,000 rows of 80 bytes each in 30 seconds or less even on a modest Oracle system using SQL Loader. The extract from Access is very dependent on the size of the CPU and the available memory.
    Hint 1: Avoid explicit or implict network traffic.
    Hint 2: Extract and load from local drives rather than networked or shared drives on other services
    Please note that this is done for efficiency of load, but has issues related to error checking, and operational scripting.
    Anything else you do or use will be slower than the method (above).
    CASE #2
    If you want to integrate this into a single JDBC program which will provide better operational management of the process, then you can simply connect to both databases in your Java program, then read the rows one at a time from Access, insert them using the Batch mechanism of JDBC to Oracle. You will also want to set the FetchSize in Oracle to a larger value then the default (i.e set it to 100 vs 10).
    Hint #3 You may want to look into alternative JDBC drivers for accessing MS Access, rather than the JDBC-ODBC bridge which is not optimized for MS Access. You may also want to consider using the OCI8 driver from Oracle rather than the thin driver. Both provide Type 4 functionality but I have heard (not experienced) that the OCI8 driver is better for managing batch style of processing like yours
    Good luck!
    Joel

  • OBIEE - table join across databases

    Hi,
    I want to join two tables that are in different databases. I want to join these tables on some condition and then be able to see data from both of them in the reports.
    Table 1 - columns A1, B1, C1
    Table 2 - columns A2, B2, D2
    Currently what we tried is
    1. create foreign key constraint between the two tables in the physical layer. Map A1 to A2, B1 to B2.
    2. create a join of two tables in BMM layer and then port that to presentation layer and then make report using these columns.
    OR
    try the approach as described on link http://oraclebizint.wordpress.com/2008/03/19/oracle-bi-ee-101332-cross-database-joins/
    in both the above mentioned ways, we are not able to see join of two tables. The link mentioned above doesn't work as we tried it multiple times already.
    We are able to see individual data from each table, but when we try to see data from them together, we get error.
    Can someone help us with this problem.
    Please email me on [email protected] if you need more info as i cant paste the confidential data here on the forum.
    Thanks in advance,
    Amit

    We made sure that the datatypes are the same in both tables.
    I will explain a bit how we did it.
    We have table T1 in database d1, table t2 in database d2. Since datatypes are different there, we actually had to create tables in physical layer and used select query to extract data from databases and get that into those tables in proper format. For example we had to do mapping to make the values of some parameters consistent (like BABY in T1 and CHILD in T2, so we used 'case when T1.parameter1='BABY' then 'CHILD' and so on for other columns).
    After that we defined forgein key constraints between these tables, then ported them to BMM layer, then to presentation layer.
    We are not getting error in terms on data types. Is there a step by step guide we can follow to get this cross database join.
    Regards,
    Amit

  • Updating metadata in OWB after modifying tables in the database

    Hi All,
    In our data warehouse, one key field will suffer a change in data precision, from number(4) to number(5). This field exists in several tables across the database and I have created a procedure to alter all related tables in Oracle (10g). Is there a way to create a similar procedure or script to modify the metadata in OWB in order to reflect the changes in the altered tables from the database? I think the script should refresh the tables in the metadata but I'm not sure if it would be necessary to sincronize or validate the related mappings.
    I'm newbie in OWB so I'm not sure whether this is achievable or not.
    Thanks in advance for your guidance.
    Regards,
    Mauricio
    Edited by: mcruz on 21/03/2010 17:07

    Below is a OMBPlus tcl script to set the precision and scale of a specific column name in all tables of the current oracle module
    Prerequisite is that you have made the connection to the OWB repository in OMBPlus (OMBCONNECT) and have set the context to the right oracle module (OMBCC and set OMBPROMPT ON, the latter to display your current context in the prompt)
    Happy scripting.
    proc set_nbr_len {p_objtyp p_col_name p_scale p_precision} {
       set tbls [OMBLIST ${p_objtyp}S]
       foreach tbl $tbls {
          set cols [OMBRETRIEVE $p_objtyp '$tbl' GET COLUMNS '$p_col_name']
          foreach col $cols {
           set dattyp [OMBRETRIEVE $p_objtyp '$tbl' COLUMN '$col' \
                         GET PROPERTIES (DATATYPE)]
           if { [string first "NUMBER" $dattyp] != -1 } {
                puts "Column $col scale & precision reset in $p_objtyp $tbl"
                    OMBALTER $p_objtyp '$tbl' MODIFY COLUMN '$col' SET PROPERTIES \
                         (SCALE, PRECISION) VALUES \
                   ('$p_scale', '$p_precision')
       OMBCOMMIT
    set_nbr_len TABLE <your column name> <your precision> <your scale>

Maybe you are looking for

  • HT1386 iPhone sync not working.

    When I create a playlist on my computer, it does not appear on my iPhone after I sync it. What do I need to do so that I can transfer the playlist from iTunes on my computer to my phone?

  • Issue with Content Repository

    Hi Gurus, We have created a CR A2 with storage type as SAP database and is successfully. The HTTP server which is being used as SAP database is just the servername, which is taken by default while creation. In our scenario, I need to mention a fully

  • Screen goes black, only answer is restarting phone...

    Every so often, my phone goes black, but the crazy part is that the top part of the screen works (the AT&T signal, clock)..I can't do anything since the HOME button doesnt really do anything, nor touching the screen, i usually just restart the phone.

  • Creating new subarea in existing Area

    Hi Guys,    I need to configure new subarea like "holiday calendar " in WorkingTime Area, can anyone tell me how to configure through SPRO tcode please .. Thanks in Advance

  • Why does the speaker in my IPAD 3 stop working intermittently?

    The speakers on my IPAD 3 with the latest operating system sometimes stop wotking, then return later.  Why?