Showing posts with label Insert. Show all posts
Showing posts with label Insert. Show all posts

Wednesday, November 18, 2015

SQL Select with Order By, Insert, Update and Delete Command

SQL Insert

SQL INSERT statement is used to add rows to a table. Insert can be used in several ways:
  • To insert a single complete row
  • To insert a single partial row
For a full row insert, SQL Query should start with “insert into “ statement followed by table name and values command followed by the values that need to be inserted into the table. To insert a full row data into employee table, SQL query should be as shown below.
Insert into employee values (1,'Joy',28)
If we want to insert data only to few columns of the table, we should specify the column names to which data is going to be inserted after table name. To insert a value into a column or set of columns (Partial),SQL query will be as shown below.
Insert into employee(EMPLOYEE_ID, EMPLOYEE_NAME) values (1,'Joy')

SQL Update

SQL Update is used to update data in a row or set of rows specified in the filter condition. The basic format of an SQL UPDATE statement is, "Update" command followed by table to be updated and SET command followed by column names and their new values followed by filter condition that determines which rows should be updated.
To update a row in employee table, SQL query will be as shown below.
Update employee set age = 35 where EMPLOYEE_NAME = 'Joy'

SQL Delete

SQL Delete is used to delete a row or set of rows specified in the filter condition. The basic format of an SQL DELETE statement is, "DELETE From" command followed by table name followed by filter condition that determines which rows should be updated. To update a row in employee table, SQL query will be as shown below.
Delete from employee where EMPLOYEE_NAME = 'Joy'

SQL Select Statement

SQL “select” statement is used to retrieve data from table. For example, to retrieve data from the table given below, following SQL select statements are used
Table Name : Employee
Employee_IDEmployee_NameAge
1John28
2Alex24
3James35
4Roy22
5Kay44
To retrieve complete data from table use SQL select Query
Select * from Employee;
Result is as given below
Employee_IDEmployee_NameAge
1John28
2Alex24
3James35
4Roy22
5Kay44
To retrieve a column from table, use following SQL select Query
Select Employee_Name from Employee
The above query will produce following result.
Employee_Name
John
Alex
James
Roy
Kay
Select Employee_Name,Age from Employee