Posts

Showing posts from 2021

Table operators in SQL

 There are few table operators available in SQL.They are Join Apply Pivot Unpivot

Types of SQL Tables

Regular table Temporary table Table variable Derived table CTE View Table-Valued function The above said are the types of available tables in sql. I hope this article would be helpful.

Drop sql table if already exists

 Sometimes the exception "Table or object already exists" comes when we create a table . To avoid this issue we will have to check whether the table is already exists or not. I hope this article would be helpful. IF OBJECT_ID(N'dbo.Orders',N'U') IS NOT NULL  DROP TABLE dbo.Orders;

Remove Table columns Dynamically in Sql

  Sometimes we may require to remove columns from a table which has enormous columns. It's a cumbersome process if we do one by one. So here I have created a stored procedure. We would have to give table name and number of columns as input.  CREATE PROC Usp_droptablecolumns (  @tablename VARCHAR(200),  @ColumnNumber INT ) AS BEGIN DECLARE @Count INT --SET @tablename='temp' --SET @ColumnNumber=1 SELECT column_id,name INTO #test FROM SYS.COLUMNS WHERE OBJECT_ID =OBJECT_ID(@tablename) SET @Count=1 WHILE(@Count<=@ColumnNumber ) BEGIN    DECLARE @ColumnName VARCHAR(200),@Query VARCHAR(500)    SELECT @ColumnName=NAME  FROM #test WHERE column_id=@Count    SET @Query='ALTER TABLE '+ @tablename +' DROP COLUMN '+ @ColumnName    --select @Query    EXEC (@Query)    SET @Count=@Count+1 END DROP TABLE #test END Execution sample Usp_droptablecolumns 'test',1

Districts of Tamilnadu at 1956

Districts of Tamilnadu at 1956 1.) Chennai 2.) Coimbatore 3.) Kanniyakumari 4.) Madurai 5.) Nilgiris 6.) Ramanathapuram 7.) Salem 8.) Thanjavur 9.) Tiruchirapalli 10.) Tirunelveli

Galaxy

Galaxy  System of billion stars, stellar remnants, interstellar gas,dust and dark matter. Milky way galaxy contains our solar system. Three major forms of Galaxy 1.Spiral 2.Elliptical 3.Irregular

The planets

There are 8 planets in our solar system.  All the planets are moving (revolution) around the Sun through its path( orbit).  First 4 planets are called "Inner planets".  Last 4 planets are called " outer planets". Except Uranus all planets are rotating from West to East. 1.) Mercury   Nearest to the Sun 2) Venus    Brightest and hottest    Seen from Earth    Called as "Earth twin","Morning Star","Evening Star" 3) Earth   Blue planet   Supports life  4) Mars     Red planet   Has polar ice caps  5) Jupiter    Largest planet    Has great red spot 6.) Saturn    Rings planet    2nd largest planet 7) Uranus   3rd Largest planet  Greenish in colour ( meethane gas)  Rotates East to West 8) Neptune   Extremely cold To remember these 8  planets I have created a mnemonic.  M y V ehicle E ngine M aintenance J umbs S lowly U p N owadays.  ...

Resetting Identity column in SQL

 Identity is one of the useful property in column. It will help us to create auto incrementing column in sql. Before the arrival of this property this requirement was done manually by adding 1 with the maximum value of the specific column. We can see this property vividly in this article.I hope this will be helpful. CREATE TABLE tblEmployee (  EmployeeId INT  IDENTITY(1,1) NOT NULL,  EmployeeName VARCHAR(50) ) Assume that we have inserted lots of records.Now we have to reset the identity value. DECLARE @maxValue INT SELECT  @maxValue=ISNULL(MAX(EmployeeId),0) FROM tblEmployee DBCC CHECKIDENT ('[tblEmployee ]',RESEED,@maxValue) Now we have reset the identity column with the maximum record count of the table. Usually we will have situation to reset IDENTITY when " Primary key violation.cannot insert duplicate value.current identity value is()" this error comes.

Break statement in C#

Image
  Break is one of the useful statement in C#. This will help us to exit the current loop. I give a example below to understand it vividly. public void BreakStatementTest() { #region Break statement test...             Console.WriteLine("Please provide Number of iteration");             int totalCount = Convert.ToInt32(Console.ReadLine());             Console.WriteLine("Please provide breakpoint number");             int breakPoint = Convert.ToInt32(Console.ReadLine());             Console.WriteLine("Total count:"+totalCount);             for (int i=0;i<totalCount;i++ )             {                 Console.WriteLine("Inside loop i=" + i);                 if (i == breakPoint) break;   ...

Row_Number() in sql

It's very useful when using paging.In laymen, It will help us create a serial number. (e.g) Select Row_Number() over( partition by statename order by employeeid ) from employees 

Abstract class

1.) Abstract class contain definition or Implementation. 2.) Class can inherit from only one abstract class. 3.) Can specify virtual to create own implementations.

Reference & value types in C#

Reference Type   Objects that stores the reference of the actual data.  (e.g) Classes, Interfaces, objects, strings, delegates. Value Types   Holds the actual value. (e.g)  Struct,bool,enum.