VALUES (value1, value2, value3,...)
IF a table Persons contains P_Id,LastName,FirstName,Address,City columns.If you want to insert values then :-
INSERT INTO Persons
VALUES (4,'Singh', 'Saurabh', 'Sector-23', 'Gurgaon')
IF NOT EXISTS (SELECT * FROM Persons WHERE P_Id = 4)
BEGIN
INSERT INTO Persons
VALUES (4,'Singh', 'Saurabh', 'Sector-23', 'Gurgaon')
END
By this way it will check firstly, if this p_id exist in the table then do not insert otherwise insert these values in the table.
Update statement :-
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value
We use If not exist statement whether there is a need to update or not.
DELETE Statement :-
DELETE From table_name WHERE some_column=some_value
Note :- Never use Delete * use Delete tableName.*
0 comments:
Post a Comment