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.
In this SQL Server query we will learn How to create table in SQL Server.
CREATE TABLE TableName ( Id INT, Name Nvarchar(500), Age INT )
In this query we will Create SQL Server table with primary key.
CREATE TABLE TableName ( Id INT PRIMARY KEY, Name Nvarchar(500), Age INT )
CREATE TABLE TableName ( Id INT IDENTITY(1,1) PRIMARY KEY, Name Nvarchar(500), Age INT )
In this SQL Server query we will learn about How to insert values into Sql Server table.
INSERT INTO TableName (Name,Age) VALUES (
'Max'
,30);
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.
INSERT INTO TableName (Name,Age) VALUES (
'Max'
,30),('John'
,28),('Jack'
,31);
In this Sql query we will update single record from a table.
UPDATE TableName SET NAME=``'Max Payne'
WHERE Id=1
In this Sql query we will update all records within a table.
UPDATE TableName SET AGE=31
In this Sql query we will delete single record from a table.
DELETE FROM TableName WHERE Id=1
In this Sql query we will delete all records from a table.
DELETE FROM TableName
In this Sql query we will select all columns from a table.
SELECT * FROM TableName
In this Sql query we will select specific columns from a table.
SELECT columnName1,ColumnName2 from TableName
A view is a virtual table created based on the result generated by SQL statement. Fields in a view are directly related to one of more tables from database.
CREATE VIEW view_name AS SELECT Id,Name,Age FROM TableName
select * From view_name
In this query we will learn about How to create stored procedure in Sql Server.
CREATE PROCEDURE getInfoFromTable AS SELECT * FROM TableName