Wednesday 24 April 2019

Youtube blocked hack play youtube video from embedded url

Youtube introduced new feature for playing video in own website or third party application using embed feature. Youtube blocked in some of schools, colleges and offices via ISP but there are many ISP didn't block embed youtube url. so let's start how to get youtube embed url from original youtube url.

1. Get the original Youtube URL
 For ex, Mobile user get https://youtu.be/EvFxAyNI9So url and Desktop user get https://www.youtube.com/watch?v=EvFxAyNI9So url.

2. Modify Youtube URL
Replace the https://www.youtube.com or https://youtu.be by https://www.youtube-nocookie.com URL.

3. Add embed into URL
After replacing url with nocookie url then add "embed" keyword into url, so url will looks like https://www.youtube-nocookie.com/embed

4. Add Dynamic part of url from original
After adding embed keyword into url. you need to add dynamic url part from original site like "EvFxAyNI9So" in above example. so our final embed Youtube url become 
 https://www.youtube-nocookie.com/embed/EvFxAyNI9So

Wednesday 12 September 2018

Transform Row data to Column data in sql

To Transfer Row data to column data in sql table using pivot.
For Example
1. We need to create table like below image.














CREATE table tblCountryCity
(
Country nvarchar(50),
City nvarchar(50)
)

Insert into tblCountryCity values ("USA","New York"), ("USA","Houston"), ("USA","Dallaas")
Insert into tblCountryCity values ("India","Hydrabad"), ("India","Banglore"), ("India","New Delhi")
Insert into tblCountryCity values ("UK","London"), ("UK","Bermingham"), ("UK","Manchester")

2. After Creating table and inserting data in table. we need to execute below query.
select Country, City1 , City2, City3
from
(
Select Country,City,
'City' + CAST (ROW_NUMBER() over (Partition By Country Order by Country) as nvarchar(10)) as ColumnSequence
from tblCountryCity
)Temp
PIVOT
(
Max(City)
For ColumnSequence in (City1, City2, City3)
)PIV

Result:-

Friday 15 December 2017

Create Split Function in Sql

You have Comma separated Document and you want to split data and store into Table that time you have to create Split Function.

Steps to Create Split Function in Sql server

Step-1:- Go to Database and Expand it.
Step-2:- Go to Programmability, Expand it and Expand Functions and Go to Table-Valued Functions.
Step-3:- Create New Multiline Fuction Option.
Step-4:- Replace Code With Below Code

CREATE FUNCTION [dbo].[SplitString] 
(
-- Add the parameters for the function here
@Input NVARCHAR(MAX),
    @Character CHAR(1)
)
RETURNS @Output TABLE(
SplitTable nvarchar(1000)
)
AS
BEGIN
-- Declare the return variable here
DECLARE @StartIndex INT, @EndIndex INT
      SET @StartIndex = 1
      IF SUBSTRING(@Input, LEN(@Input) - 1, LEN(@Input)) <> @Character
      BEGIN
            SET @Input = @Input + @Character
      END
      WHILE CHARINDEX(@Character, @Input) > 0
      BEGIN
            SET @EndIndex = CHARINDEX(@Character, @Input)
           
            INSERT INTO @Output(SplitTable)
            SELECT SUBSTRING(@Input, @StartIndex, @EndIndex - 1)
           
            SET @Input = SUBSTRING(@Input, @EndIndex + 1, LEN(@Input))
      END
      RETURN

END

Step-5:- After Executing Above Command, You can Find Out dbo.SplitString Function in Table-valued Function Panel. Your Split Function Successfully Created.

Step-6:- Now to Execute or Use SplitString Function using Following Command
SELECT SplitTable FROM SplitString('@InputString','@Separate Character');
For Example,
SELECT SplitTable FROM SplitString('Brij,Patel,TSE,Computer',',') Executing this Command.

List out Table's Primary Key Referencing Foreign Key Tables

If you have lots of tables in your high-end Database that time you are confusing about Primary and Foreign Key relationship, Because There is Many To Many Cross Relationship Possible. To Find out Table's Primary Key references with other tables as Foreign Key in database. You can easily List out Referencing tables of PK_Table.
For Example,

You use AdventureWorks Database. Now you want to find Foreign Key referencing of BusinessEntityID from person.Person table from AdventureWorks. Execute Following Command.

Use AdventureWorks
GO

SELECT
    c.CONSTRAINT_NAME,
    cu.TABLE_NAME AS ReferencingTable, cu.COLUMN_NAME AS ReferencingColumn,
    ku.TABLE_NAME AS ReferencedTable, ku.COLUMN_NAME AS ReferencedColumn
    FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS c
INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE cu
ON cu.CONSTRAINT_NAME = c.CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE ku
ON ku.CONSTRAINT_NAME = c.UNIQUE_CONSTRAINT_NAME
WHERE ku.TABLE_NAME = 'Person(PK_Table)'

You will get List of Foreign Key References like,


To Find Out Tables list From Database which Contains Specific Columnname

If You want to Figure out Particular ColumnName Used Which Tables in Database To resolve Confusion about same name. You can Do easily using Single Command
For Example,

You use Default Database AdventureWorks. and You Want to Find out "ProductId" Columnname use Which Tables in Database. You can Execute Following Command.

USE AdventureWorks2012
GO
SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%ProductID(ColumnName)%'
ORDER BY schema_name, table_name;

To Get All Table List which is used in Stored Procedure

To Get All Table List Which is be a Part of Stored Procedure, You can get all Tables List Using Single Command in Sql Server.
For Example,

If You use Default AdventureWorks Database. If You Will get Some Stored Procedure like (uspGetBillOfMaterials) Looks like

CREATE PROCEDURE [dbo].[uspGetBillOfMaterials]
    @StartProductID [int],
    @CheckDate [datetime]
AS
BEGIN
    SET NOCOUNT ON;

    -- Use recursive query to generate a multi-level Bill of Material (i.e. all level 1
    -- components of a level 0 assembly, all level 2 components of a level 1 assembly)
    -- The CheckDate eliminates any components that are no longer used in the product on this date.
    WITH [BOM_cte]([ProductAssemblyID], [ComponentID], [ComponentDesc], [PerAssemblyQty], [StandardCost], [ListPrice], [BOMLevel], [RecursionLevel]) -- CTE name and columns
    AS (
        SELECT b.[ProductAssemblyID], b.[ComponentID], p.[Name], b.[PerAssemblyQty], p.[StandardCost], p.[ListPrice], b.[BOMLevel], 0 -- Get the initial list of components for the bike assembly
        FROM [Production].[BillOfMaterials] b
            INNER JOIN [Production].[Product] p
            ON b.[ComponentID] = p.[ProductID]
        WHERE b.[ProductAssemblyID] = @StartProductID
            AND @CheckDate >= b.[StartDate]
            AND @CheckDate <= ISNULL(b.[EndDate], @CheckDate)
        UNION ALL
        SELECT b.[ProductAssemblyID], b.[ComponentID], p.[Name], b.[PerAssemblyQty], p.[StandardCost], p.[ListPrice], b.[BOMLevel], [RecursionLevel] + 1 -- Join recursive member to anchor
        FROM [BOM_cte] cte
            INNER JOIN [Production].[BillOfMaterials] b
            ON b.[ProductAssemblyID] = cte.[ComponentID]
            INNER JOIN [Production].[Product] p
            ON b.[ComponentID] = p.[ProductID]
        WHERE @CheckDate >= b.[StartDate]
            AND @CheckDate <= ISNULL(b.[EndDate], @CheckDate)
        )
    -- Outer select from the CTE
    SELECT b.[ProductAssemblyID], b.[ComponentID], b.[ComponentDesc], SUM(b.[PerAssemblyQty]) AS [TotalQuantity] , b.[StandardCost], b.[ListPrice], b.[BOMLevel], b.[RecursionLevel]
    FROM [BOM_cte] b
    GROUP BY b.[ComponentID], b.[ComponentDesc], b.[ProductAssemblyID], b.[BOMLevel], b.[RecursionLevel], b.[StandardCost], b.[ListPrice]
    ORDER BY b.[BOMLevel], b.[ProductAssemblyID], b.[ComponentID]
    OPTION (MAXRECURSION 25)
END;

Now Execute Following Command to Get Used Table in SP

USE AdventureWorks2012
GO

SELECT objects.name As suspected_dependencies
FROM   sys.procedures
 INNER
  JOIN sys.all_sql_modules
    ON all_sql_modules.object_id = procedures.object_id
 LEFT
  JOIN sys.objects
    ON objects.name <> procedures.name
   AND all_sql_modules.definition LIKE '%' + objects.name + '%'
WHERE  procedures.name = 'uspGetBillOfMaterials(Your Stored Procedure)'

You will get List of Tables.

To Get All Stored Procedure List which used particular Table


If You want to find out A particular Table From Database used which Stored Procedure in DB. You can Get Stored ProcedureName with Respected Schema Class.
For Example,

If you Use AdventureWorks Database. Now You want to Find out person.Person Table Used Which Stored Procedure among Database. You can use Following Commands in Sql Server.

Use AdventureWorks
GO

SELECT * FROM sys.dm_sql_referencing_entities('person.Person', 'OBJECT')

Youtube blocked hack play youtube video from embedded url

Youtube introduced new feature for playing video in own website or third party application using embed feature. Youtube blocked in some of ...