Monday 4 September 2017

SQL Server - Scripts


This page contains sql scripts to find the MS SQL server metadata. Check INFORMATION_SCHEMA and SYS objects which has metadata catalogs that are available in SQL Server.
  • Check foreign key relationship between tables.
SELECT
   OBJECT_NAME(f.parent_object_id) TableName,
   COL_NAME(fc.parent_object_id,fc.parent_column_id) ColName,
   f.name,
   OBJECT_NAME(f.referenced_object_id) Reference_Table,
    COL_NAME(fc.referenced_object_id,fc.referenced_column_id) RefColName
FROM
   sys.foreign_keys AS f
INNER JOIN
   sys.foreign_key_columns AS fc
      ON f.OBJECT_ID = fc.constraint_object_id
INNER JOIN
   sys.tables t
      ON t.OBJECT_ID = fc.referenced_object_id
WHERE
   OBJECT_NAME (f.referenced_object_id) in  ('TABLE_NAME')
  • Check table size
  • SELECT 
        t.NAME AS TableName,
        s.Name AS SchemaName,
        p.rows AS RowCounts,
        SUM(a.total_pages) * 8 AS TotalSpaceKB, 
        CAST(ROUND(((SUM(a.total_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB,
        SUM(a.used_pages) * 8 AS UsedSpaceKB, 
        CAST(ROUND(((SUM(a.used_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS UsedSpaceMB, 
        (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB,
        CAST(ROUND(((SUM(a.total_pages) - SUM(a.used_pages)) * 8) / 1024.00, 2) AS NUMERIC(36, 2)) AS UnusedSpaceMB
    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
    

    References:

    Thursday 13 April 2017

    Angular Tips and Tricks

    Angular Tips and Tricks


    Router Configuration Details:

    export class AppRoutingModule {
        // inspect router configuration and auth guard configs
        constructor(router: Router) {
            console.log("Routes: ", JSON.stringify(router.config, undefined, 2));
        }
    }



    Enable Tracing

    RouterModule.forRoot(appRoutes,
                   {enableTracing: true}
                 {preloadingStrategy: PreloadAllModules})


    Control Value Accessor 

    A ControlValueAccessor acts as a bridge between the Angular forms API and a native element in the DOM.[1]






    Tuesday 28 April 2015

    Tips & Tricks



    VI editor shows the error terminal too wide 

    Connected to solaris server through putty and try to edit a file with vi editor. Following error display.

    (user:current)% vi Makefile64.backup  Terminal too wide

    Resolution

    Increase the number of columns using stty command . This command used to manage the characteristics of the terminal.

    stty columns 100 
     stty --version,  stty -a or --all,  stty -g, stty --help 










    References:

    Tuesday 17 March 2015

    Test SyntaxHighlighter


    SyntaxHighlighter
    


    PHP
    <?php
    $example = range(0, 9);
    foreach ($example as $value)
    {
     echo $value;
    }
    

    JAVA
    public class TestJava {
    
     /**
      * @param args
      */
     public static void main(String[] args) {
      // TODO Auto-generated method stub
    
     }
    
    }


    SQL
    SELECT *
    FROM DUAL;
    


    Shell Script
    #!/bin/bash
    clear
    which bash
    echo "Good morning, world."
    


    Tested in following browsers:

    • Chrome Version 41.0.2272.89 m 
    • Firefox 36.0.1 
    • IE 10.0.23

    Reference links: