INSERT,UPDATE,DELETE,LIKE,SELECT DISTINCT IN SQL SERVER

INSERT,UPDATE,DELETE,LIKE,SELECT DISTINCT IN SQL SERVER


INSERT



The INSERT INTO statement is used to insert new records in a table.




Syntax


INSERT INTO table_name VALUES (value1,value2,value3,...);





INSERT INTO table_name (column1,column2,column3,...)VALUES (value1,value2,value3,...);


Example

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal','Tom B. Erichsen','Skagen 21','Stavanger','4006','Norway');


UPDATE

The UPDATE statement is used to update existing records in a table.

Syntax

UPDATE table_name SET column1=value1,column2=value2,...WHERE some_column=some_value;

 Example

UPDATE Customers SET ContactName='Alfred Schmidt', City='Hamburg'WHERE CustomerName='Alfreds Futterkiste';


SELECT

The SELECT statement is used to select data from a database.

Syntax


SELECT column_name,column_name FROM table_name;

SELECT * FROM table_name;

DELETE


The DELETE statement is used to delete rows in a table.

Syntax


DELETE FROM table_name
WHERE some_column=some_value;

DELETE FROM Customers
WHERE CustomerName='Alfreds Futterkiste' AND ContactName='Mari
a Anders';

Delete All Data


DELETE FROM table_name;

SELECT DISTINCT


In a table, a column may contain many duplicate values; and sometimes you only want to list the different (distinct) values.
The DISTINCT keyword can be used to return only distinct (different) values.

Syntax

SELECT DISTINCT column_name,column_name
FROM table_name; 

SELECT DISTINCT City FROM Customers;


LIKE Operator

Syntax

SELECT column_name(s)  FROM table_name WHERE column_name LIKE pattern;

The following SQL statement selects all customers with a City starting with the letter "s":

Example
SELECT * FROM Customers WHERE City LIKE 's%';

The following SQL statement selects all customers with a City ending with the letter "s":

Example
SELECT * FROM Customers WHERE City LIKE '%s';

The following SQL statement selects all customers with a Country containing the pattern "land":
Example
SELECT * FROM Customers WHERE Country LIKE '%land%';