Structured Query Language

.What is SQL? Structured Query Language (SQL. is a nonprocedural language for database manipulation and retrieval of information. pronounced as sequel).

Interactive data-manipulation language (DML) includes a query language based on both the relational algebra and the tuple relational calculus. are disallowed. deleting relations and modifying relation schemas 2. Data Definition Language (DDL) provides commands for defining relation schemas. 7. It contains commands to insert tuples into. Java. Transaction control includes commands for specifying the beginning and end of transactions 5. Embedded SQL and dynamic SQL defines how SQL statements can be embedded within general purpose programming languages such as C. Integrity in which SQL DDL includes commands for specifying the integrity constraints that the data stored in the database must satisfy so that updates. Authorization in which SQL DDL includes commands for specifying access rights to relations and views .The SQL language has several parts : 1. COBOL. delete tuples from and modify tuples in the database 3. 6. which violate integrity constraints. C++. View definition includes commands for defining views 4.

The SELECT Statement .


Manipulating the Column Names .



Simple conditional retriveal .

This can be achieved using the Logical Operators like .Complex Conditional Retrieval Complex Conditional Retrieval can be done by combining two or more conditional statements while retrieving the data.

When using the BETWEEN keyword. .Usage of BETWEEN Keyword The BETWEEN keyword is used to check for a range of values. both the values are included in the conditional clause.

To view the list of all employees whose names starts with the letter A:  Select * from employee where emp_name like ‘A%’ Select * from employee where grade like ‘_1’ .Usage of LIKE keyword The LIKE keyword is used to search for a specific pattern in a particular column.

unless specified.’ Rate=price From titles ORDER BY price DESC . phone AS Telephone.The ORDER BY Clause When we require sorting the data in a particular order. au_lname. city. we can use the ORDER BY clause. ‘Category’=type. state FROM authors ORDER BY au_lname ASC. au_fname ASC Select ‘Book’=title. By default this clause sorts the specified column in ascending order. SELECT au_fname.

The GROUP BY Clause SQL Server provides a method of grouping the result set using the GROUP BY clause. The GROUP BY clause summarizes the result set into the groups defined in the query using aggregate functions. ‘Minimum’=min(price). ‘Maximum’=max(price) From titles Where price > 10 Group By type . to produce the data based on a condition SELECT type. The Having clause further restricts the result set. .

‘Average Price’=avg(price) From Titles Where Price > 10 Group by type Having avg(price) > 15 select dept_code.Select type. sum (salary) from employee where age > 30 group by dept_code having sum (salary) > 10000 order by sum (salary) desc. .

Sign up to vote on this title
UsefulNot useful