Skip to main content

SQL Server Tutorial - Tables

In this article we will learn about some of the mostly used SQL Server queries every developer should know. 
These queries can be asked you as an Interview Question or they are handy for you in your day to day tasks.

1. Create Table:

In this SQL Server query we will learn How to create table in SQL Server.

1
2
3
4
5
6
CREATE TABLE TableName
(
   Id INT,
   Name Nvarchar(500),
   Age INT
)  

2. Create table with primary key:

In this query we will Create SQL Server table with primary key.
1
2
3
4
5
6
CREATE TABLE TableName
(
   Id INT PRIMARY KEY,
   Name Nvarchar(500),
   Age INT
)

3. Create table with primary key and Identity Column:

1
2
3
4
5
6
CREATE TABLE TableName
(
   Id INT  IDENTITY(1,1) PRIMARY KEY,
   Name Nvarchar(500),
   Age INT
)

4. Insert values into SQL Server table:

In this SQL Server query we will learn about How to insert values into Sql Server table.
1
INSERT INTO TableName (Name,Age) VALUES ('Max',30);

5. Insert multiple rows in a single query:

In this Sql query we will learn How to Insert Multiple Rows in a Single SQL Query. This query is very important and generally asked in .Net Interview questions.
1
2
INSERT INTO TableName (Name,Age)
VALUES ('Max',30),('John',28),('Jack',31);

6. Update query:

Update single record:

In this Sql query we will update single record from a table.
1
UPDATE TableName SET NAME='Max Payne' WHERE Id=1

Update all records:

In this Sql query we will update all records within a table.
1
UPDATE TableName SET AGE=31

7. Delete query:

Delete single record:

In this Sql query we will delete single record from a table.
1
DELETE FROM TableName WHERE Id=1

Delete multiple records:

In this Sql query we will delete all records from a table.
1
DELETE FROM TableName

8. Select:

Select all columns from a tables:

In this Sql query we will select all columns from a table.
1
SELECT * FROM TableName

Select specific columns:

In this Sql query we will select specific columns from a table.
1
SELECT columnName1,ColumnName2 from TableName

Comments

Popular posts from this blog

Scenario : Cloud Computing

Create Web API in Asp.Net Core MVC with Example

Introduction : Here we will learn how to create web api in  asp.net  core mvc with example or  asp.net  core mvc rest web api tutorial with example or  asp.net  core mvc restful api with example or implement web api using asp.net  core with examples. By using  asp.net  core mvc web api templates we can easily implement restful web api services based on our requirements. To create web api first we need to create new project for that Open visual studio  à  Go to File menu  à select New  à  Project like as shown below  Now from web templates select  Asp.Net Core Web Application  ( .NET Core ) and give name ( CoreWebAPI ) to the project and click  OK  button like as shown below. Once we click  OK  button new template will open in that select  Web API  from Asp.Net Core templates like as shown below Our asp.net core web api project s...

SQL Server Tutorial - Date functions

1. Get month names with month numbers: In this query we will learn about  How to get all month names with month number in SQL Server . I have used this query to bind my dropdownlist with month name and month number. 1 2 3 4 5 6 7 8 9 10 11 12 ;WITH months(MonthNumber) AS (      SELECT 0      UNION ALL      SELECT MonthNumber+1      FROM months      WHERE MonthNumber < 12 ) SELECT DATENAME(MONTH,DATEADD(MONTH,-MonthNumber,GETDATE())) AS [MonthName],Datepart(MONTH,DATEADD(MONTH,-MonthNumber,GETDATE())) AS MonthNumber FROM months ORDER BY Datepart(MONTH,DATEADD(MONTH,-MonthNumber,GETDATE())) ; 2. Get name of current month: In this query we will learn about  How to get name of current month in SQL Server . 1 select DATENAME(MONTH, GETDATE()) AS CurrentMonth 3. Get name of day: In this query we wil...