Monday, 16 October 2017

Tech Trends that dominated 2017

Hi guys in this article I will explain the top Tech trends that were a hot topic whole year. Moreover as its my first post on Linkedin so Please give me your valuable feedback :)

1.Iot and Smart Home

Internet of things , connecting almost everything we use. Iot has a great impact in our lives. It starts from smart connected devices that we wear on our body that collect personal data. Fitness trackers are by far the most popular type of wearable.

Internet of Things is also about all smart home appliances from smart thermostats such as Hive , intelligent fridges to other connected sockets. Best example is "Amazon Echo"

With Emergence of Iot there is also a need of more security measures aroused.
Moreover there are new Open source tools and platforms that concern with Iot like "GRAKN.AI"

2. AR and VR.

Augmented reality is the power of computers to show the real world in more meaningful details and specific details you want to know about real world. 

Virtual Reality is capability of computers to generate efficient graphics by his own simulations that looks like real. 
There are many advancements in both these technologies this year.There are Virtual Worlds created with power of 3D and internet. Moreover these two technologies has been made usable for trainings causing less resource consumptions.

3. Machine Learning 

Machine learning means learning from data. It Enables different technologies to use data efficiently and find the result the user want.
A lot of research work is there on internet on Machine Learning.
DenseNet algorithm provided by FAIR is at top now a days.


4. Automation

Iot is cutting prices of automation. There have been 3 layer systems instead of 5 layer systems in the industry. Mobile Autonomy is also a hot topic in 2017. There have been very advancements in database administrations, even Oracle has launched an Autonomous Database12c. Moreover CRM and ERP softwares are also automating their processes.

5. Humanized Big Data

 Information should be processed in such a way that non-data scientists can also derive clear answers. Sooner there would be chat bots that will interact businessmen's regarding their business decisions. Hadoop is open source software for dealing with Big Data. Techniques used in this year to humanisze data are as follows
  1. Association rule learning
  2. Classification tree analysis
  3. Genetic algorithms
  4. Regression analysis
  5. Sentiment analysis
  6. Social network analysis

6. Physical-Digital Integrations

It is necessity of the era to have physical things done digitally. Bigger companies like Amazon and Walmart will automate the order and supply and even try-out products, to a store in your town. 

Engineering tools and models  are used in the design, construction, and operation of a city infrastructure and utilize a suite of technologies and processes to assist this integration. Progress of a company employees could be integrated with their tasks and after analyses budgets could pe decreases.


7. Everything On-Demand

ed People are Trying to get each and everything on demand by few clicks. Uber is providing such services. Moreover, a doctor could be called out on internet. No-body know to which extent we are integrated with the internet.  






Saturday, 14 October 2017

How to Learn Fast

Its weekend a as an IT professional worked hard , searched many people linked to many other people. read blogs about how to learn fast, listened to TED talks, after all this I came to point is that too learn fast you should follow these points

Stop searching about learning and try to learn actually
focus on what you want to learn
start it by putting something to eat and drink while breaks in learning
Remember long journey starts with a very small step
Talk to people of your field not the others
dont be reluctant in expressing your experience

Yolo , Leave bloging and dp some Learning , time to go . . .

Tuesday, 10 October 2017


Query to find space usage in a Tablespace

Suppose a tablesapace is full and you want to find space used by different objects like tables and index , then use folllowing query to get results


SELECT owner, segment_name, segment_type, partition_name, ROUND(bytes/(1024*1024),2) SIZE_MB, tablespace_name

FROM DBA_SEGMENTS

WHERE SEGMENT_TYPE IN ('TABLE', 'TABLE PARTITION', 'TABLE SUBPARTITION','INDEX', 'INDEX PARTITION', 'INDEX SUBPARTITION', 'TEMPORARY', 'LOBINDEX', 'LOBSEGMENT', 'LOB PARTITION')
AND TABLESPACE_NAME  like 'Name%'
ORDER BY bytes DESC;
SQL server 2008 R2 Scheduling Backup

There are many changes developed in SQLserver. Old versions of sqlserver are less compatible with newer tool like Power shell, this is the reason due to which we face problems in scheduling backups in Express Edition of older Sql server. Here I will use SQLCMD for scheduling the backup of a Database.

Well it is little bit tricky that how can i schedule database backup in SQL Server 2008 R2!! its too old

So i followed the steps as follows


Creating Tables required :
USE Database_name  --change to new database name
GO
IF object_id('ScheduledJobs') IS NOT NULL
    DROP TABLE ScheduledJobs

GO   
CREATE TABLE ScheduledJobs
(
    ID INT IDENTITY(1,1),
    ScheduledSql nvarchar(max) NOT NULL,
    FirstRunOn datetime NOT NULL,
    LastRunOn datetime,
    LastRunOK BIT NOT NULL DEFAULT (0),
    IsRepeatable BIT NOT NULL DEFAULT (0),
    IsEnabled BIT NOT NULL DEFAULT (0),
    ConversationHandle uniqueidentifier NULL
)
GO

IF object_id('ScheduledJobsErrors') IS NOT NULL
    DROP TABLE ScheduledJobsErrors   
CREATE TABLE ScheduledJobsErrors
(
    Id BIGINT IDENTITY(1, 1) PRIMARY KEY,
    ErrorLine INT,
    ErrorNumber INT,
    ErrorMessage NVARCHAR(MAX),
    ErrorSeverity INT,
    ErrorState INT,
    ScheduledJobId INT,
    ErrorDate DATETIME NOT NULL DEFAULT GETUTCDATE()
)

IF OBJECT_ID('usp_RemoveScheduledJob') IS NOT NULL
    DROP PROC usp_RemoveScheduledJob

GO


Creating Procedures required:
CREATE PROC usp_RemoveScheduledJob
    @ScheduledJobId INT
AS   
    BEGIN TRANSACTION
    BEGIN TRY
        DECLARE @ConversationHandle UNIQUEIDENTIFIER
        -- get the conversation handle for our job
        SELECT    @ConversationHandle = ConversationHandle
        FROM    ScheduledJobs
        WHERE    Id = @ScheduledJobId

        -- if the job doesn't exist return
        IF @@ROWCOUNT = 0
            RETURN;

        -- end the conversation if it is active
        IF EXISTS (SELECT * FROM sys.conversation_endpoints WHERE conversation_handle = @ConversationHandle)
            END CONVERSATION @ConversationHandle

        -- delete the scheduled job from out table
        DELETE ScheduledJobs WHERE Id = @ScheduledJobId         
    END TRY
    BEGIN CATCH
        IF @@TRANCOUNT > 0
        BEGIN
            ROLLBACK;
        END
        INSERT INTO ScheduledJobsErrors (
                ErrorLine, ErrorNumber, ErrorMessage,
                ErrorSeverity, ErrorState, ScheduledJobId)
        SELECT    ERROR_LINE(), ERROR_NUMBER(), 'usp_RemoveScheduledJob: ' + ERROR_MESSAGE(),
                ERROR_SEVERITY(), ERROR_STATE(), @ScheduledJobId
    END CATCH

GO
IF OBJECT_ID('usp_AddScheduledJob') IS NOT NULL
    DROP PROC usp_AddScheduledJob





GO
CREATE PROC usp_AddScheduledJob
(
    @ScheduledSql NVARCHAR(MAX),
    @FirstRunOn DATETIME,
    @IsRepeatable BIT   
)
AS
    DECLARE @ScheduledJobId INT, @TimeoutInSeconds INT, @ConversationHandle UNIQUEIDENTIFIER   
    BEGIN TRANSACTION
    BEGIN TRY
        -- add job to our table
        INSERT INTO ScheduledJobs(ScheduledSql, FirstRunOn, IsRepeatable, ConversationHandle)
        VALUES (@ScheduledSql, @FirstRunOn, @IsRepeatable, NULL)
        SELECT @ScheduledJobId = SCOPE_IDENTITY()
        print 'added to the table'
        -- set the timeout. It's in seconds so we need the datediff
        SELECT @TimeoutInSeconds = DATEDIFF(s, GETDATE(), @FirstRunOn);
        -- begin a conversation for our scheduled job
        BEGIN DIALOG CONVERSATION @ConversationHandle
            FROM SERVICE   [//ScheduledJobService]
            TO SERVICE      '//ScheduledJobService',
                            'CURRENT DATABASE'
            ON CONTRACT     [//ScheduledJobContract]
            WITH ENCRYPTION = OFF;

        -- start the conversation timer
        BEGIN CONVERSATION TIMER (@ConversationHandle)
        TIMEOUT = @TimeoutInSeconds;
        -- associate or scheduled job with the conversation via the Conversation Handle
        UPDATE    ScheduledJobs
        SET        ConversationHandle = @ConversationHandle,
                IsEnabled = 1
        WHERE    ID = @ScheduledJobId
        IF @@TRANCOUNT > 0
        BEGIN
            COMMIT;
        END
    END TRY
    BEGIN CATCH
        IF @@TRANCOUNT > 0
        BEGIN
            ROLLBACK;
        END
        INSERT INTO ScheduledJobsErrors (
                ErrorLine, ErrorNumber, ErrorMessage,
                ErrorSeverity, ErrorState, ScheduledJobId)
        SELECT    ERROR_LINE(), ERROR_NUMBER(), 'usp_AddScheduledJob: ' + ERROR_MESSAGE(),
                ERROR_SEVERITY(), ERROR_STATE(), @ScheduledJobId
    END CATCH

GO
IF OBJECT_ID('usp_RunScheduledJob') IS NOT NULL
    DROP PROC usp_RunScheduledJob

GO






CREATE PROC usp_RunScheduledJob
AS
    DECLARE @ConversationHandle UNIQUEIDENTIFIER, @ScheduledJobId INT, @LastRunOn DATETIME, @IsEnabled BIT, @LastRunOK BIT

    SELECT    @LastRunOn = GETDATE(), @IsEnabled = 0, @LastRunOK = 0
    -- we don't need transactions since we don't want to put the job back in the queue if it fails
    BEGIN TRY
        DECLARE @message_type_name sysname;           
        -- receive only one message from the queue
        RECEIVE TOP(1)
                @ConversationHandle = conversation_handle,
                @message_type_name = message_type_name
        FROM ScheduledJobQueue

        -- exit if no message or other type of message than DialgTimer
        IF @@ROWCOUNT = 0 OR ISNULL(@message_type_name, '') != 'http://schemas.microsoft.com/SQL/ServiceBroker/DialogTimer'
            RETURN;

        DECLARE @ScheduledSql NVARCHAR(MAX), @IsRepeatable BIT               
        -- get a scheduled job that is enabled and is associated with our conversation handle.
        -- if a job fails we disable it by setting IsEnabled to 0
        SELECT    @ScheduledJobId = ID, @ScheduledSql = ScheduledSql, @IsRepeatable = IsRepeatable
        FROM    ScheduledJobs
        WHERE    ConversationHandle = @ConversationHandle AND IsEnabled = 1

        -- end the conversation if it's non repeatable
        IF @IsRepeatable = 0
        BEGIN           
            END CONVERSATION @ConversationHandle
            SELECT @IsEnabled = 0
        END
        ELSE
        BEGIN
            -- reset the timer to fire again in one day
            BEGIN CONVERSATION TIMER (@ConversationHandle)
                TIMEOUT = 86400; -- 60*60*24 secs = 1 DAY
            SELECT @IsEnabled = 1
        END
        -- run our job
        EXEC (@ScheduledSql)

        SELECT @LastRunOK = 1
    END TRY
    BEGIN CATCH       
        SELECT @IsEnabled = 0

        INSERT INTO ScheduledJobsErrors (
                ErrorLine, ErrorNumber, ErrorMessage,
                ErrorSeverity, ErrorState, ScheduledJobId)
        SELECT    ERROR_LINE(), ERROR_NUMBER(), 'usp_RunScheduledJob: ' + ERROR_MESSAGE(),
                ERROR_SEVERITY(), ERROR_STATE(), @ScheduledJobId

        -- if an error happens end our conversation if it exists
        IF @ConversationHandle != NULL       
        BEGIN
            IF EXISTS (SELECT * FROM sys.conversation_endpoints WHERE conversation_handle = @ConversationHandle)
                END CONVERSATION @ConversationHandle
        END

    END CATCH;
    -- update the job status
    UPDATE    ScheduledJobs
    SET        LastRunOn = @LastRunOn,
            IsEnabled = @IsEnabled,
            LastRunOK = @LastRunOK
    WHERE    ID = @ScheduledJobId
GO

IF EXISTS(SELECT * FROM sys.services WHERE NAME = N'//ScheduledJobService')
    DROP SERVICE [//ScheduledJobService]

IF EXISTS(SELECT * FROM sys.service_queues WHERE NAME = N'ScheduledJobQueue')
    DROP QUEUE ScheduledJobQueue

IF EXISTS(SELECT * FROM sys.service_contracts  WHERE NAME = N'//ScheduledJobContract')
    DROP CONTRACT [//ScheduledJobContract]



GO
CREATE CONTRACT [//ScheduledJobContract]
    ([http://schemas.microsoft.com/SQL/ServiceBroker/DialogTimer] SENT BY INITIATOR)

CREATE QUEUE ScheduledJobQueue
    WITH STATUS = ON,
    ACTIVATION (   
        PROCEDURE_NAME = usp_RunScheduledJob,
        MAX_QUEUE_READERS = 20, -- we expect max 20 jobs to start simultaneously
        EXECUTE AS 'dbo' );


Creating Service 

CREATE SERVICE [//ScheduledJobService]
    AUTHORIZATION dbo
    ON QUEUE ScheduledJobQueue ([//ScheduledJobContract])


Backup and Schedule




SET QUOTED_IDENTIFIER OFF
GO
Declare @StartDate datetime;
set @StartDate=cast (cast(year(Getdate()) as varchar)  + '-' +  cast(Month(getdate())  as varchar) +'-'+ cast(day(Getdate())  as varchar) +' 11:20:00' as datetime) 
DECLARE @ScheduledSql nvarchar(max), @RunOn datetime, @IsRepeatable BIT
SELECT    @ScheduledSql = "DECLARE @backupTime DATETIME, @backupFile NVARCHAR(512);
                          SELECT @backupTime = GETDATE(),
                                 @backupFile = 'E:\main\MetaData Backup\name.bak';
                          BACKUP DATABASE database_name TO DISK = @backupFile WITH NOFORMAT, INIT,  NAME = N'database_name-Full Database Backup', SKIP, NOREWIND,
NOUNLOAD,  STATS = 10;",
        @RunOn = @StartDate ,
        @IsRepeatable = 1

EXEC usp_AddScheduledJob @ScheduledSql, @RunOn, @IsRepeatable
GO