Understanding Common SQL statements

The commonly used SQL statements are: 1): Select 2): Insert 3): Update 4): Delete

Understanding Common SQL statements

Understanding Common SQL statements

     

The commonly used SQL statements are:

1): Select
2): Insert
3): Update
4): Delete

SQL Select statement:

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

Syntax: Select column_names FROM table_name;

The result from a SQL query is stored in a resultset. The SELECT statement has mainly three clauses.

1). Select
2.) From
3). Where

The Select specifies the table columns that are retrieved. The From clause tells from where the tables has been accessed. The Where clause specifies which tables are used. The Where clause is optional, if not used then all the table rows will be selected.

We can see that we have used semicolon at the end of the select statement. It is used to separate each SQL statement in database systems which helps us to execute more than one SQL statement in the same call to the server.

SQL INSERT Statement:

This statement allows you to insert a single or multiple records into the database. We can specify the name of the column in which we want to insert the data.

Syntax: Insert into table_name values (value1, value2..);

The Insert statement has mainly three clauses.

1). Insert: It specifies which table column has to be inserted in the table.
2). Into : It tells in which the data will be stored.
3). Values: In this we insert the values we have to insert.

We can also specify the columns for which we want to insert data.

The UPDATE Statement:

The Update statement is used to modify the data in the table. Whenever we want to update or delete a row then we use the Update statement.

The syntax is :

UPDATE table_name Set colunm_name = new_value WHERE column_name = some_name;

The Update statement has mainly three clauses.

1). UPDATE: It specifies which table column has to be updated.
2). Set: It sets the column in which the data has to be updated.
3). Where: It tells which tables are used.

SQL DELETE Statement:

This delete statement is used to delete rows in a table.

Systax:

DELETE FROM table_name WHERE column_name = some_name;

The Delete statement has following clauses.

1). Delete: It specifies which table column has to be deleted.
2). From: It tells from where the Table has been accessed.
3). Where: It tells which tables are used.