Question 1. How to Swap the values of two columns in SQL Server ?
Answer: Suppose that we have a table with records in database as below:

Now how could you solve this tricky task? The solution is very simple, we need to perform this through a query:
- UPDATE Product1 SET vProductName=vManfacturer , vManfacturer=vProductName

The solution is shown below after completing the update query:

Note: Data type of both the columns should be same and also length should be enough to hold the swapped column data otherwise data will be truncated.
Question 2: How do we find out total free space in Server?
Answer: To find out Server available disk space follow the below query:
Query:
Answer: To find out Server available disk space follow the below query:
Query:
- xp_fixeddrives
Question 3: What is .MDF, .LDF and .NDF file in SQL Server?
Answer: SQL Server databases have three types of files:
- Primary data files: It is the starting point of the database and points to the other files in the database. Every database has one primary data file.
Extension: .mdf. (master data file) - Secondary data files: It comprise of the data files other than the primary data file. Some databases may not have any secondary data files, while others have multiple secondary data files.
Extension: .ndf.( next data file) - Log files: It holds all of the log information used to recover the database. There must be at least one log file for each database, although there can be more than one.
Extension: .ldf.( log data file)
Example: Click on database properties then select files option:

Question 4: Why do we use Cast function?
Answer: Cast function is used to convert Datatype of expression into other Datatypes.
Syntax: CAST( Expression AS type into (New Datatype ) )
Example 1:

In the following output the Cast Function is converting 14.85 datatype value into new datatype provided format as of Integer value output.
Example 2. In the following pic I used Getdate function with date with above output. Now I used Cast function that will change the getdate output into Varchar Output.

Question 5: How to insert values to identity column in SQL Server?
Answer: Cast function is used to convert Datatype of expression into other Datatypes.
Syntax: CAST( Expression AS type into (New Datatype ) )
Example 1:
- SELECT CAST(14.85 AS int);

In the following output the Cast Function is converting 14.85 datatype value into new datatype provided format as of Integer value output.
Example 2. In the following pic I used Getdate function with date with above output. Now I used Cast function that will change the getdate output into Varchar Output.

Question 5: How to insert values to identity column in SQL Server?
Answer: Identity field is usually used as a Primary Key. When you insert a new record into your table, it will automatically assign an incremented value from the previous entry.
Syntax: IDENTITY [(seed, Increment)] Note: Seed is the Initial Value)
Example:
- CREATE TABLE Customer ( ID int IDENTITY, Name varchar(100), Address varchar(200) )
Or
- CREATE TABLE new_employees ( id_num int IDENTITY(100,15), fname varchar (20), lname varchar(30))
We can perform this through Table design: Select Database Table, then right click on Design option: Select the Column Name, in Column Properties click Yes and provide seed and increment in it.

Question 6: How to use SELECT INTO statement?
Answer: We use SELECT INTO statement to copy an existing table data into a new table creation.
Syntax: SELECT ( * or elements) INTO Newtable_Name FROM tables WHERE conditions;
Example: I have a already created table with name CustomerOrders under database (Trainee) as seen below:

Now I am using Select Into Statement:
- SELECT * INTO India FROM CustomerOrders WHERE Amount=20.12
You can see dbo.India is created with output shown below.

Note: The new_table must not already exist. If it does already exist, the SELECT INTO statement will raise an error.

SubashPosted Sep 7, 2016, 8:24 AM
Good article
Rajeesh MenothPosted Nov 30, 2015, 1:07 AM
Thanks for sharing..
Santhakumar MunuswamyPosted Nov 28, 2015, 2:24 AM
Nice share
Harshad PansuriyaPosted Nov 27, 2015, 11:09 PM
Nice one
Mukesh KumarPosted Nov 26, 2015, 11:52 PM
Good
Raja TPosted Nov 26, 2015, 11:27 PM
Nice, Thanks for sharing
Jaipal ReddyPosted Nov 26, 2015, 11:26 PM
nice
Yashwant VishwakarmaPosted Nov 26, 2015, 11:06 PM
Awesome one dude !!
Upendra Pratap ShahiPosted Nov 26, 2015, 12:09 PM
nice..