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

.NET Core 2.0 Changes – 4 Key Things to Know

1. .NET Standard 2.0 Expanded APIs & the Ability to Reference Full Framework Libraries .NET Standard broadens the set of APIs available to include a lot of the missing features. It now supports 32,000+ APIs. It is now much easier to port your code to a .NET Standard library without major code changes. One of the biggest problems with .NET Core was the lack of third-party libraries. For example, when 1.0 came out, popular logging libraries like log4net were not even available (it is now). However, this was really only a problem if you wanted to deploy your app on Mac or Linux. You could have used .NET Core and targeted full .NET framework and not had these issues. .NET Standard 2.0 has added a  new compatibility shim  that will enable any .NET Core app to reference any full framework library. 2. Expanded OS Support One of the big goals with .NET Core is portability across multiple operating systems. Including desktops, servers, and even mobile. Microsoft ...

ASP.NET Core - MVC Design Pattern

The MVC (Model-View-Controller) design pattern is a design pattern that's actually been around for a few decades, and it's been used across many different technologies, everything from Smalltalk to C++ to Java and now in C# and .NET as a design pattern to use when you're building a user interface. The MVC design pattern is a popular design pattern for the user interface layer of a software application. In larger applications, you typically combine a model-view-controller UI layer with other design patterns in the application, like data access patterns and messaging patterns. These will all go together to build the full application stack. The MVC separates the user interface (UI) of an application into the following three parts − The Model  − A set of classes that describes the data you are working with as well as the business logic. The View  − Defines how the application’s UI will be displayed. It is a pure HTML which decides how the UI is going to loo...

ASP.NET Core - Create New Project

You can start building a new ASP.NET Core Application from the  File → New Project  menu option. On the New Project dialog box, you will see the following three different templates for Web projects − ASP.NET Web Application  − The simple ASP.NET application templates . ASP.NET Core Web Application (.NET Core)  − This will start you with a crossplatform compatible project that runs on the .NET Core framework. ASP.NET Core Web Application (.NET Framework)  − This starts a new project that runs on the standard .NET Framework on Windows. In the left pane, select  Templates → Visual C# → Web  and in the middle pane select the ASP.NET Core Web Application (.NET Core) template. Let us call this application  FirstAppDemo  and also specify the Location for your ASP.NET Core project and then Click OK. In the above dialog box, you can select a specific template for the ASP.NET application from the available ASP.NET Core Templates. ...