7bcee3a Unit V SQL Basics
7bcee3a Unit V SQL Basics
SQL Basics
R.Sheeba M.Sc.,M.Phil.,
Assistant professor,
Department of computer science
Madurai sivakasi nadars pioneer Meenakshi women’s
College, poovanthi
Structured Query Language (SQL)
SQL is a standard data access language used to interact with relational databases.
Microsoft SQL server – To use SQL to create fairly sophisticated SQL scripts for stored
procedures and triggers.
SQL Statements
Syntax
The basic syntax of the ORDER BY clause is as follows −
The SQL ORDER BY clause is used to sort the data in ascending or descending order,
based on one or more columns. Some databases sort the query results in an ascending
order by default.
Example: Select Statement
Here, the SQL command selects the first_name and last_name of all Customers.
Here, the SQL command selects all columns of the Customers table.
SQL SELECT WHERE Clause
A SELECT statement can have an optional WHERE clause.
The WHERE clause allows us to fetch records from a database table
that matches specified condition(s).
For example,
Here, the SQL command fetches age and country fields of all customers
whose country is USA.
The SQL Update
In SQL, the UPDATE statement is used to edit the existing record in
a database table.
Syntax:
Example,
Here, the SQL command changes the value of the first_name column will be Johnny if
customer_id is equal to 1.
Update Multiple Values in a Row
Here, the SQL command changes the value of the first_name column to Johnny and
last_name to Depp if customer_id is equal to 1.
Update Multiple Records
The UPDATE statement can update multiple records at once.
For example,
Here, the SQL command changes the value of the country column to NP if age is
22. If there are more than one rows with age equals to 22, all the matching rows
will be edited.
The SQL Insert Statement
In SQL, the INSERT INTO statement is used to insert new record(s) in
a database table.
Syntax:
INSERT INTO TABLE_NAME (column1, column2, column3,...columnN) VALUES (value1, value2, value3,...valueN);
For example,
Here, the SQL command will delete a row from the Customers table where customer_id is
5.
Delete all Rows in a Table
The WHERE clause determines which rows to delete. However, we can
delete all rows at once if we omit the WHERE clause.
For example,