Query to find tables with excessive initial extent settings

After loading a database dump we found many tables occupying large space due to large initial extents storage parameter but with very few rows and am trying to determine if it would be worth the effort to reorganize the entire schema. In other words, we are looking for a query to compare the estimated actual space that would be occupied by the table rows vs. the current size to see the space savings if we were to reorganize.
I hacked out a script to calculate the estimated size using the table stats (or 64K if estimate is lower) and compared that vs. the extents allocated to each table but this seems a rather inexact way of doing it. Is there a more accurate approach?
Doing this on Oracle database 10.2.0.4 on Windows Server 2003 SE
SELECT a.table_name,
           b.table_size_MB,
           ROUND((a.num_rows * a.avg_row_len) / (1024 * 1024),2) calc_size_MB, 
           b.table_size_MB - GREATEST(ROUND((a.num_rows * a.avg_row_len) / (1024 * 1024),2), 0.0625) savings_MB
  FROM dba_tables a,
      (SELECT segment_name, sum(bytes)/(1024*1024) table_size_MB
         FROM dba_extents
        WHERE tablespace_name like 'PMDX' and segment_type = 'TABLE'
        GROUP BY segment_name) b
WHERE a.owner = 'CAS' and a.table_name = b.segment_name
ORDER BY b.table_size_MB desc
TABLE_NAME                     TABLE_SIZE_MB CALC_SIZE_MB SAVINGS_MB
TPM06_POL_DATA_WRK_PREV                  640       493.46     146.54
TPM06_POL_DATA_WRK_CURR                  640       496.57     143.43
TPM06_POL_DATA_201006                    640        496.8      143.2
TPM06_POL_DATA_201005                    640       494.87     145.13
TPM06_POL_DATA_201004                    640       490.45     149.55
TPM07_MOV_DTLS_WRK                       256       198.66      57.34
...

Hi,
Didn't you check the dba_extents view with respect to the tables which you estimated.
After loading a database dump we found many tables occupying large space due to large initial extents storage parameterYou might have modified the initial extent size before to your load by pre-created tables ,which might helped out with current situation prior to this as you might be well known with your current database. Does the segement using Autoallocate or Uniform. What is the block size of DB.
- Pavan Kumar N

Similar Messages

  • Query to find records with more than 2 decimal places

    I have written the below query to find records with more than 2 decimal places, but it is returning records with decimal places 1 & 2.
    The datatype of the AMT column is NUMBER (without any precision).
    SELECT amt  FROM amount_table
    WHERE substr(amt, instr(amt, '.')) LIKE '.%'
           AND length(substr(amt, instr(amt, '.') + 1)) > 2Output:-
    AMT
    *41591.1*
    *275684.82*
    *64491.59*
    *3320.01*
    *6273.68*
    *27814.18*
    *30326.79*
    131.8413635
    162.5352898
    208.5203816
    8863.314632
    22551.27856
    74.716992
    890.0158441
    2622.299682
    831.6683841
    *1743.14*
    2328.195877
    3132.453438
    5159.827334
    3.236234727
    37.784
    Thanks

    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    create table amount_table
      LINE_NUMBER        NUMBER not null,
      FEE_AMT            NUMBER not null
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (60208, 41591.1);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (60213, 275684.82);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (60238, 64491.59);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (63026, 3320.01);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (59906, 6273.68);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (83111, 27814.18);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (83114, 30326.79);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (2112395, 131.8413634682);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (2112399, 162.5352898104);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (2112402, 208.5203815738);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (2112403, 8863.3146321954);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (2112406, 22551.2785551322);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (2112407, 74.716992);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (2112410, 890.015844079);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (2112411, 2622.2996817048);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (2112414, 831.6683840698);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (2112415, 1743.14);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (2112418, 2328.1958771886);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (2112419, 3132.4534379886);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (2112422, 5159.8273341686);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (2112423, 3.2362347266);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (2112426, 37.784);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (2112427, 198.7423503696);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (2112430, 0.7220848332);
    insert into amount_table (LINE_NUMBER, FEE_AMT)
    values (2112433, 12.4149375254);

  • Find - tables with largest number of records?

    Hi,
    I need to find tables with largest number of records. Any transaction show this details?
    aRs

    Go to transaction DB02,  then click on the button that reads,  "Space Statistics", the dialog box, click ok, leave the "*" for all tables,   In the next screen put your cursor in the appropriate column labeled as Rows and click the sort button.  Now you will see your biggest tables at the top of the list.
    Regards,
    Rich Heilman

  • How to fix tables created with wrong initial extents

    1.We have many tables which are created with very large intial extents. Is there a way to reduce or resize initial extent?
    2.When I export the *.dmp is about 200MG, but the tablespace is more than a gig full. Why is that?
    3.I have a table with about 300,000 rows and calculated the table size to be around 86M. Should I create the initial extent here to be around 100M?
    4.I tried to do alter table ExampleTable deallocate unused, but did not help why is that?
    OBJECT_NAME = EMP
    TOTAL_BLOCKS = 16296
    TOTAL_BYTES = 133496832
    UNUSED_BLOCKS = 4915
    UNUSED BYTES = 40263680
    LAST_USED_EXTENT_FILE_ID = 9
    LAST_USED_EXTENT_BLOCK_ID = 23250
    LAST_USED_BLOCK = 11381
    PL/SQL procedure successfully completed.
    SQL> analyze table ibs_spec_value compute statistics;
    Table analyzed.
    SQL> select empty_blocks, empty_blocks*8192 unused_bytes
    2 from dba_tables
    3 where table_name='IBS_SPEC_VALUE' and owner='SPEC';
    EMPTY_BLOCKS UNUSED_BYTES
    4915 40263680
    SQL> ALTER TABLE SPEC.IBS_SPEC_VALUE DEALLOCATE UNUSED;
    Table altered.
    SQL> select empty_blocks, empty_blocks*8192 unused_bytes
    2 from dba_tables
    3 where table_name='IBS_SPEC_VALUE' and owner='SPEC';
    EMPTY_BLOCKS UNUSED_BYTES
    4915 40263680
    Thank you,
    Avanti.

    1.We have many tables which are created with very large intial extents. Is there a way to reduce or resize initial extent?
    export/import and CTAS.
    2.When I export the *.dmp is about 200MG, but the tablespace is more than a gig full. Why is that?
    Probably it is due of inefficient on managing the objects, which are heavily taken by tables/indexes. Tables/indexes were created oversize than estimation of data size.
    3.I have a table with about 300,000 rows and calculated the table size to be around 86M. Should I create the initial extent here to be around 100M?
    Yes, it is possible. Usually split into 2-5 extents is better.
    4.I tried to do alter table ExampleTable deallocate unused, but did not help why is that?
    OBJECT_NAME = EMP
    TOTAL_BLOCKS = 16296
    TOTAL_BYTES = 133496832
    UNUSED_BLOCKS = 4915
    UNUSED BYTES = 40263680
    LAST_USED_EXTENT_FILE_ID = 9
    LAST_USED_EXTENT_BLOCK_ID = 23250
    LAST_USED_BLOCK = 11381
    PL/SQL procedure successfully completed.
    SQL> analyze table ibs_spec_value compute statistics;
    Table analyzed.
    SQL> select empty_blocks, empty_blocks*8192 unused_bytes
    2 from dba_tables
    3 where table_name='IBS_SPEC_VALUE' and owner='SPEC';
    EMPTY_BLOCKS UNUSED_BYTES
    4915 40263680
    SQL> ALTER TABLE SPEC.IBS_SPEC_VALUE DEALLOCATE UNUSED;
    Table altered.
    SQL> select empty_blocks, empty_blocks*8192 unused_bytes
    2 from dba_tables
    3 where table_name='IBS_SPEC_VALUE' and owner='SPEC';
    EMPTY_BLOCKS UNUSED_BYTES
    4915 40263680
    The next paragraph is guoted from Oracle documentation :
    "Use the deallocate_unused_clause to explicitly deallocate unused space at the end of the table, partition or subpartition, overflow data segment, LOB data segment, or LOB index and makes the space available for other segments in the tablespace. You can free only unused space above the high water mark (that is, the point beyond which database blocks have not yet been formatted to receive data)".
    Most probably on your case there is no unused block over the last used block on this table. So the deallocate function doesn't give any effect. As you described, the last used block is 11381 which is get from TOTAL_BLOCKS minus UNUSED_BLOCKS.

  • Select query on a table with 13 million of rows

    Hi guys,
    I have been trying to perform a select query on a table which has 13 millions of entries however it took around 58 min to complete.
    The table has 8 columns with 4 Primary keys looks like below:
    (PK) SegmentID > INT
    (PK) IPAddress > VARCHAR (45)
    MAC Address > VARCHAR (45)
    (PK) Application Name > VARCHAR (45)
    Total Bytes > INT
    Dates > VARCHAR (45)
    Times > VARCHAR (45)
    (PK) DateTime > DATETIME
    The sql query format is :
    select ipaddress, macaddress, sum(totalbytes), applicationname , dates,
    times from appstat where segmentid = 1 and datetime between '2011-01-03
    15:00:00.0' and '2011-01-04 15:00:00.0' group by ipaddress,
    applicationname order by applicationname, sum(totalbytes) desc
    Is there a way I can improve this query to be faster (through my.conf or any other method)?
    Any feedback is welcomed.
    Thank you.
    Mus

    Tolls wrote:
    What db is this?
    You never said.
    Anyway, it looks like it's using the Primary Key to find the correct rows.
    Is that the correct number of rows returned?
    5 million?
    Sorted?I am using MySQL. By the way, the query time has been much more faster (22 sec) after I changed the configuration file (based on my-huge.cnf).
    The number of rows returned is 7999 Rows
    This is some portion of the my.cnf
    # The MySQL server
    [mysqld]
    port = 3306
    socket = /var/lib/mysql/mysql.sock
    skip-locking
    key_buffer = 800M
    max_allowed_packet = 1M
    table_cache = 256
    sort_buffer_size = 1M
    read_buffer_size = 1M
    read_rnd_buffer_size = 4M
    myisam_sort_buffer_size = 64M
    thread_cache_size = 8
    query_cache_size= 16M
    log = /var/log/mysql.log
    log-slow-queries = /var/log/mysqld.slow.log
    long_query_time=10
    # Try number of CPU's*2 for thread_concurrency
    thread_concurrency = 6
    Is there anything else I need to tune so it can be faster ?
    Thanks a bunch.
    Edited by: user578505 on Jan 17, 2011 6:47 PM

  • Query on a table with indexed date field

    I have a table with a date column which is indexed. If I run a query like "select column1 where date_field='20-JAN-04' for example it is fast and uses index.
    If I run select column1 where date < '20-JAN-04' it is slow and doesnt use the index. I logged a TAR and Oracle told me that this is to be expected as not using the index in this case is the most effiecient way of doing the query.
    Now my concept of an index is like the index of Yellow Pages(telephone directory) for example. In this example if I look for a name that is say "Halfords" or below, I can see all entries for Halfords and all the way to ZZZ in one block.
    I just cant see , in a common sense way why Oracle wont use the index in this type of query.
    George

    Using the concept of a telephone directory is wrong. In a telephone directory you have all information order by the name. However in your table (if it is not an IOT) you don't have all information/rows ordered by your date_field. Rather think at the document "Oracle9i Database Concepts" and it's index.
    Let's say you want to find all indexed words larger then "ISO SQL standard" (ok that doesn't make sense but it is just an example). So would it be faster to read the whole document or to lookup each word in the index and then read the entire page (Oracle block) to find the word.
    It's not allways easy to know in advance if the query will be faster over the index or a full table scan. what you need to do is to well analyze (dbms_stats) the table and it's index, in most cases Oracle chooses the right way. You may also use the hint /*+ index(table_name index_name) */ and will see if it would be faster over the index or not.
    A good document about that subject is:
    http://www.ioug.org/tech/IOUGinDefense.pdf
    HTH
    Maurice

  • Backend query to find metrics with thresholds

    Hi,
    Is there a way to query the backend tables in repository database to find the metrics with thresholds on a database.I want to findout the missing warning/critical thresholds for all the targets.Any inputs for this may be helpful to me.
    Thanks.

    You might want to create a User Deinfed Metric that does a query on the SYSMAN schema to find out.
    Checkout
    Oracle® Enterprise Manager Extensibility Guide
    10g Release 5 (10.2.0.5)
    http://download.oracle.com/docs/cd/B16240_01/doc/em.102/b40007/toc.htm
    For description of all SYSMAN views to select your data
    Regards
    Rob
    http://oemgc.wordpress.com

  • How to find table with colum that not support by data pump network_link

    Hi Experts,
    We try to import a database to new DB by data pump network_link.
    as oracle statement, Tables with columns that are object types are not supported in a network export. An ORA-22804 error will be generated and the export will move on to the next table. To work around this restriction, you can manually create the dependent object types within the database from which the export is being run.
    My question, how to find these tables with colum that that are object types are not supported in a network export.
    We have LOB object and oracle spital SDO_GEOMETRY object type. our database size is about 300G. nornally exp will takes 30 hours.
    We try to use data pump with network_link to speed export process.
    How do we fix oracle spital users type SDO_GEOMETRY issue during data pump?
    our system is 32 bit window 2003 and 10GR2 database.
    Thanks
    Jim
    Edited by: user589812 on Nov 3, 2009 12:59 PM

    Hi,
    I remember there being issues with sdo_geometry and DataPump. You may want to contact oracle support with this issue.
    Dean

  • Spatial overlay queries involving tables with different spatial extents

    We are using GeoMedia Professional 6.1 with an Oracle 10g database. For validating geometry, we use a standard minimum bounding rectangle (MBR) that is fairly tight to our city boundary. Some city departments are requesting that we extend the spatial limits to create a larger MBR for some new features. This will involve using a new SDO_DIMINFO array in the MDSYS.SDO_GEOM_METADATA_TABLE and creating new spatial indexes. It is our intention to leave the existing features "as-is" with the original MBR and spatial indexes. I have done some preliminary testing in GeoMedia and have not run into any issues when doing spatial queries involving features with different MBRs. Spatial intersections, spatial differences and spatial filters seem to complete in a reasonable amount of time, even with large data sets. Does anyone have any experience using different MBRs with Oracle spatial overlay queries? Are there any other potential issues we should be aware of when working with tables that are created with different spatial extents such as performance?

    Luc ... Thank you for supplying the URL for Simon Greener’s website. This article supports information we already received from our GIS software provider.
    With regards to your questions: One of the checks carried out in our “ValidateGeometry” procedure is to ensure that a new or modified geometry is within the bounding rectangle defined by the SDO_DIMINFO. An error is raised if the user tries to add a polygon that is well beyond the city boundary rather than within the prescribed city area. Currently, we do not use different MBR’s as layer extents (there are only a couple of exceptions). We are in the process of conducting system and performance testing to identify potential issues that may be encountered when tables created with expanded upper and lower bounds are used in downstream applications such as intranet/internet web maps. We are still trying to identify any potential “hotspots”.

  • Need a query to find Table Dependancy

    Hi Experts,
    I am in a need to find out which are all tables refer to particular table 'ABC' and / or it's column 'column_1', since I am new to environment and have about 500 + tables.
    Please tell me what are the various ways, I can achieve above requirement?
    Regards,
    MS

    user_cons_columns
    Information about accessible columns in constraint definitions
    OWNER
    Owner of the constraint definition
    CONSTRAINT_NAME
    Name associated with the constraint definition
    TABLE_NAME
    Name associated with table with constraint definition
    COLUMN_NAME
    Name associated with column or attribute of object column specified in the constraint definition
    POSITION
    Original position of column or attribute in definition
    Also try this, DBMS_METADATA
    set long 9999
    select dbms_metadata.get_ddl('TABLE','ABC') FROM DUAL;
    Edited by: rajeysh on Jun 21, 2011 2:44 AM
    Edited by: rajeysh on Jun 21, 2011 2:44 AM

  • How do I avoid ORA-01473 when querying hierarchial on tables with VPD predicates

    My question is how to circumvent what seems to be a limitation i ORACLE, if at all possible. Please read on.
    When using VPD (Virtual Private Database) predictaes on a table and performing a hierarchial query on that table I get the following error message:
    ORA-01473: cannot have subqueries in CONNECT BY CLAUSE
    My query may look like the folwing:
    SELECT FIELD
    FROM TABLE
    START WITH ID = 1
    CONNECT BY PRIOR ID = PARENT
    As my predicate contains a query in it self, I suspect that the implicit augmentation of the predicate results in a query that looks like:
    SELECT FIELD
    FROM TABLE
    START WITH ID = 1
    CONNECT BY PRIOR ID = PARENT
    AND OWNER IN (SELECT OWNER FROM TABLE2 WHERE ...)
    at least, when executing a query like the one above (with the explicit predicate) I get the identical error message.
    So my question is:
    Do you know of any way to force the predicate to augment itslef onto the WHERE-clause? I would be perfectly happy with a query that looks like:
    SELECT FIELD
    FROM TABLE
    START WITH ID = 1
    CONNECT BY PRIOR ID = PARENT
    WHERE OWNER IN (SELECT OWNER FROM TABLE2 WHERE ...)
    or do you know of any fix/patch/release to ORACLE that allows you to include subqueries in the CONNECT BY-clause and eliminates the error message?

    The WHERE clause or AND clause applies to the line directly above it. Please see the examples of valid and invalid queries below, which differ only in the placement of the WHERE or AND clause. If this is not sufficient, please provide some sample data and desired output to clarify what you need.
    -- valid:
    SQL> SELECT     empno,
      2            mgr,
      3            deptno
      4  FROM     emp
      5  WHERE     deptno IN
      6            (SELECT deptno
      7             FROM     dept
      8             WHERE     dname = 'RESEARCH')
      9  START WITH mgr = 7566
    10  CONNECT BY PRIOR empno = mgr
    11  /
         EMPNO        MGR     DEPTNO                           
          7788       7566         20                           
          7876       7788         20                           
          7902       7566         20                           
           800       7902         20                           
    -- invalid:
    SQL>
    SQL> SELECT     empno,
      2            mgr,
      3            deptno
      4  FROM     emp
      5  START WITH mgr = 7566
      6  CONNECT BY PRIOR empno = mgr
      7  WHERE     deptno IN
      8            (SELECT deptno
      9             FROM     dept
    10             WHERE     dname = 'RESEARCH')
    11  /
    WHERE      deptno IN
    ERROR at line 7:
    ORA-00933: SQL command not properly ended
    -- valid:
    SQL>
    SQL> SELECT     empno,
      2            mgr,
      3            deptno
      4  FROM     emp
      5  START WITH mgr = 7566
      6  AND     deptno IN
      7            (SELECT deptno
      8             FROM     dept
      9             WHERE     dname = 'RESEARCH')
    10  CONNECT BY PRIOR empno = mgr
    11  /
         EMPNO        MGR     DEPTNO                           
          7788       7566         20                           
          7876       7788         20                           
          7902       7566         20                           
           800       7902         20                           
    -- invalid:
    SQL>
    SQL> SELECT     empno,
      2            mgr,
      3            deptno
      4  FROM     emp
      5  START WITH mgr = 7566
      6  CONNECT BY PRIOR empno = mgr
      7  AND     deptno IN
      8            (SELECT deptno
      9             FROM     dept
    10             WHERE     dname = 'RESEARCH')
    11  /
    FROM       emp
    ERROR at line 4:
    ORA-01473: cannot have subqueries in CONNECT BY clause

  • Query in a table with similary fields

    Hi,<br>
    I have a table with fields like :<br>
    - DB_AMOUNT_01<br>
    - DB_AMOUNT_02<br>
    - DB_AMOUNT_03<br>
    - CR_AMOUNT_01<br>
    - CR_AMOUNT_02<br>
    - CR_AMOUNT_03</p>
    I would like to create a function like :<br>
    AMOUNT(PERIOD)</p>
    If I choose 1, the query would do :<br>
    DB_AMOUNT_01 + CR_AMOUNT_01</p>
    If I choose 2, the query would do :<br>
    DB_AMOUNT_02 + CR_AMOUNT_02</p>
    Is it possible ?<br>
    Ideally, I would rather not use IF, THEN, ELSE like :<br>
    <font face="Courier New" size="2">IF MyChoose = 1 THEN<br>
    ELSEIF MyChoose = 2 THEN<br>
    ELSE<br>
    END IF</font></p>
    I prefer to be able to write somethings like :<br>
    <font face="Courier New" size="2">SELECT DB_AMOUNT || MyChoose + CR_AMOUNT || MyChoose</font></p>
    Thank you very much.</p>
    <font color="#008080"><i><b>Patrick</b></i></font>

    try this:
    create or replace function my_amount( period in varchar2) return number
    as
    v_str varchar2(100);
    v_str2 varchar2(1000);
    v_amount number;
    begin
    v_str := 'DB_AMOUNT_'||period || ' + ' || ' CR_AMOUNT_' || period;
    v_str2 := 'SELECT SUM(' || v_str || ' ) FROM myTable ';
    EXECUTE IMMEDIATE v_str2 INTO v_amount;
    return v_amount;
    end my_amount;
    This is intended to be pseudo-code to show the flow of logic. You can modify v_str2 to write the SQL according to your needs ... just make sure that the SQL returns only one record. Also, you may want to add Exception handling.
    The input period is in format '01' or '02' if the period is in single digits.
    Shakti
    http://www.impact-sol.com
    Developers of Guggi Oracle - Tool for DBAs and Developers

  • SQL: Find table with max no. of rows

    I have a table containing list of table names for each owner; as
    ## Table: db_tables
    OWNER TABLE_NAME
    a ta_1
    a ta_2
    a ta_3
    b tb_1
    b tb_2
    c tc_1
    Now, i want to know the table with max. no. of rows for each owner
    Plz....can anyone gimme a solution for the above ......

    Assuming 10g and above:
    SQL>  SELECT owner,
                 MAX(table_name) KEEP (DENSE_RANK FIRST ORDER BY XMLQUERY (t RETURNING CONTENT).getnumberval() DESC) table_name,
                 MAX(XMLQUERY (t RETURNING CONTENT).getnumberval()) cnt
        FROM (SELECT owner,table_name,    'count(ora:view("' || table_name || '"))' t
                FROM all_tables
               WHERE owner IN ('MICHAEL','SCOTT'))
               GROUP BY owner
    OWNER                          TABLE_NAME                            CNT
    MICHAEL                        SERVICE_ZIP                       1000000
    SCOTT                          EMP                                    14
    2 rows selected.

  • Advice with a query to find Accounts with activities within a given period ONLY

    Hello there,
    I am relatively new to Microsoft T-SQL and I was wondering if someone could help shed some light into a requirement I got...
    I have two tables in a database. One with accounts, and another with activities for such accounts. He is a simple diagram:
    *NOTE: Dates are in the DD/MM/YYYY format.
    Here is what I need to do:
    I need to get a list of all the accounts where the LAST activity was created in a date range, along with a count of activities that fall in such range. The idea behind this is to find out accounts with no activity after a certain period.
    I can certainly accounts with activities in a given range -- but that does not mean that there was no activities after the range.
    For example, if I look for Accounts with activities between Feb/2014 and Mar/2014, this query should NOT return the Contoso account, because it ha an activity after Mar/2014 (i.e.: Meeting with John on 15/Apr/14).
    Another example: If I query accounts with activities from 01/Jan/2014 and 03/Apr/2014, it should ONLY return the Adventureworks account:
    Adventureworks (3)
    [the number in parenthesis is the count of activities in that given time]
    This is because all other accounts had activities after 03/Apr/2014.
    Could someone please advise the best way to construct this query?
    Thanks in advance for the help!
    Regards,
    P.

    SELECT * FROM tbl WHERE CreatiinDate BETWEEN @firstactivities AND  lastactivites
    AND NOT EXISTS 
    (SELECT * FROM tbl t WHERE CreatiinDate>=@lastactivites
    AND
    tbl.AccountID=T.AccountID )
    OR
    SELECT * FROM tbl WHERE
    AccountID  NOT IN (SELECT
    AccountID FROM
    tbl t WHERE CreatiinDate>@lastactivites) 
    AND CreationDate BETWEEN
    @firstactivities AND  lastactivites
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Query to find tables whcih are renamed

    Hi,
    Can anyone help me with a query to list the tables which are renamed or a ttribute of a specific table which will give the result.
    Example: If database is renamed then create_date from sys.databases gives the database renamed.
    Similar I want for tables
    Thanks

    Hi cnk_gr,
    Actually I dont want to rename tables want to list the tables whicha re renamed comaring the time.
    Can you suggest how could this be achievedusing sp_rename?
    Thanks.
    Hi Priyanka,
               As for as i know, there is no way to track the changes done by sp_rename, unless if you already plan this case as
    cnk_gr mentioned with adding extendedproperty, or you can write your version of SP_rename like SP_rename1 which internally calling SP_rename and track the changes on a table
    below is the code the changes the object name, i dont know what %% the statement is doing, but i think it may be updating the objectname in physical location where the objectname is saved(just the reference is changed from old name to new name)
    -- update the object name
    EXEC %%Object(ID = @objid).SetName(Name = @newname)
    May be you can compare the schema between similar other server like reporting server or restore a backup, which doesn't have the rename applyed and find out the differnence.
    Note: when you rename a table in SSMS, it internally calling sp_rename to change the table name
    Thanks
    Saravana Kumar C

Maybe you are looking for

  • Long render times in Premiere CS6

    Hello everyone. I am exporting my first ever Premiere show. It is a 82 min. long program, HDV 1080i. Everything is rendered - the entire timeline is green. It took well over 2 hours to render, which seems excessive to me, though I did have filters on

  • Scheduling of ALV report in Background

    Hi, Presntly I want to schedule ALV report in the Background, The reprot output which I am getting is desirable. Please let me know which parameter I need to set it for processing ALV report in the background. Thanks in Advance Irfan Hussain

  • How to Getting ABAP through SAP NetWeaver XI

    Hi all, Please, Help me for the following secenario, I Installed SAP Netweaver 2004 in my system ( ABAP stack and J2EE Stack ),both are working fine.the thing is i am not able to access all the tables in abap.example MARA,MARC ,VBAK like that lot of

  • Event behaviors in CS3

    Hi all, I did import a "SWF" small movie into a new flash document.... the idea is to create two buttons, STOP/PAUSE and PLAY. But I can't figure this out using the behaviors tool from the windows menu.. In the first layer is the movie "sample.swf" i

  • Changing enabled background images based on jpeg EXIF data.

    Hello, I have a huge mess of desktop backgrounds in a folder that I have been sorting through with exif keywords. I currently have it set up to cycle through every image, but it would be nice to enable or disable images in the slideshow based on thei