Create table, Insert, Update, Delete, Search in table in SQL SERVER

We will study syntax of Create table, Insert, Update, Delete, Search in table in SQL SERVER and example:- 

Syntax of Create table:-
  

   
CREATE TABLE tblName
(
Column1 data_type, Column1 data_type, Column1 data_type, Column1 data_type,......
)


Example:-

CREATE TABLE tblStudentRecord
(
Name varchar(100), Rollno int primary key, Branch varchar(30),Email varchar(100),Address varchar(200)
)



Insert record in table :- 

Syntax :-
  

INSERT INTO tblName values(data1, data2, data3, data4, data5,.......)

                      OR

INSERT INTO tblName (Column1, Column1, Column1, Column1.......) values(data1, data2, data3, data4, data5,.......)



Example :-
  

INSERT INTO tblStudentRecord VALUES('Santosh kumar singh',1001,'Information Technology','sa@gmail.com','A-3033')
INSERT INTO tblStudentRecord VALUES('Er. Reena Tanti',1002,'ECE','err@gmail.com','T-387, Gaya')
INSERT INTO tblStudentRecord VALUES('Chandan kumar',1003,'CSE','chn@gmail.com','Gaya')
INSERT INTO tblStudentRecord VALUES('Nand kishor kumar',1004,'BCA','nk@gmail.com','A-3033,Darbhanga')
INSERT INTO tblStudentRecord VALUES('Abhinav kumar',1005,'MCA','ab@gmail.com','H-837')





Update record in table :- 

Syntax :-
  

UPDATE TABLE_NAME SET COLUMN_NAME1='SOME DATA', COLUMN_NAME1='SOME DATA',COLUMN_NAME1='SOME DATA',......WHERE CONDITION



Now, i want to update record of Chandan kumar. I want to change Branch CSE to ECE. Before update table look like as below:-
  

UPDATE tblStudentRecord SET Branch='ECE' WHERE Rollno=1003



After update table look like as below 



Delete record from table :- 

Syntax :-
  

DELETE FROM TABLE_NAME WHERE CONDITION



Example :- I want to Delete record of Chandan kumar from tblStudentRecord table:- 
  

DELETE FROM tblStudentRecord WHERE Rollno=1003



After delete Chandan kumar record from tblStudentRecord table and table look like this:- 


Search record from table :- 

Syntax :-
  

--FOR GET ALL RECORD
SELECT * FROM TABLE_NAME

--FOR PARTICULAR COLUMNS

SELECT COLUMN1, COLUMN2, COLUMN3, WHERE CONDITION



Example :- 
  

--FOR GET ALL RECORD
SELECT * FROM tblStudentRecord


--FOR PARTICULAR COLUMNS SUCH AS NAME AND BRANCH
SELECT Name,Branch FROM tblStudentRecord WHERE Rollno=1001

No comments:

Post a Comment

How to register multiple implementations of the same interface in Asp.Net Core?

 Problem: I have services that are derived from the same interface. public interface IService { } public class ServiceA : IService { ...