Data Type: - What Is SQL? Write It's Data Type. Ans

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 34

Q . What is SQL? Write it’s data type.

Ans. SQL (Structured Query Language) is used to perform operations on


the records stored in database such as updating records, deleting records,
creating and modifying tables, views etc.

o SQL stands for Structured Query Language.


o It is designed for managing data in a relational database
management system (RDBMS).
o It is pronounced as S-Q-L or sometime See-Qwell.
o SQL is a database language, it is used for database creation,
deletion, fetching rows and modifying rows etc.
o SQL is based on relational algebra and tuple relational calculus.

DATA TYPE
SQL Data Type is an attribute that specifies the type of data of any
object. Each column, variable and expression has a related data type in
SQL. You can use these data types while creating your tables. You can
choose a data type for a table column based on your requirement.

SQL Server offers six categories of data types for your use which are
listed below-

1. Binary Datatypes:
2. Exact Numeric Datatype:

3. Approximate Numeric Datatype

4. Character String Datatype 


5. Unicode Character String Datatype

6. Date and Time Datatype

DDL
 DDL or Data Definition Language actually consists of the SQL commands that can
be used to define the database schema. It simply deals with descriptions of the
database schema and is used to create and modify the structure of database
objects in database.

Examples of DDL commands:

CREATE

DROP

ALTER
 CREATE – is used to create the database or its objects (like table, index,
function, views, store procedure and triggers).
 DROP – is used to delete objects from the database.
ALTER-is used to alter the structure of the database.

RENAME
ADD
ADD is used to add columns into the existing table. Sometimes we may require
to additional information, in that case we do not require to create the whole
database again, ADD comes to our rescue.
DML(Data Manipulation Language)  

The SQL commands that deals with the manipulation of data present
in database belong to DML or Data Manipulation Language and this
includes most of the SQL statements.

1. SELECT 
2. INSERT
3. UPDATE

SELECT – is used to retrieve data from the a database


INSERT – is used to insert data into a table.

UPDATE– is used to update existing data within a table.

Difference between Alter and Update


UPDATE
SELECT & INSERT
DCL(Data Control Language)
DCL includes commands such as GRANT and REVOKE which mainly
deals with the rights, permissions and other controls of the database
system.

Examples of DCL commands:


1. GRANT-gives user’s access privileges to database.
2. REVOKE-withdraw user’s access privileges given by using the GRANT
command.

Primary Key
A primary key is a special relational database table column (or combination of
columns) designated to uniquely identify all table records.
A primary key’s main features are:

 It must contain a unique value for each row of data.


 It cannot contain null values.

A primary key is either an existing table column or a column that is specifically


generated by the database according to a defined sequence.

Foreign Key
A FOREIGN KEY is a key used to link two tables together.

A FOREIGN KEY is a field (or collection of fields) in one table that refers to
the PRIMARY KEY in another table.

The table containing the foreign key is called the child table, and the table
containing the candidate key is called the referenced or parent table.

Unique Key
A unique key is a set of one or more than one fields/columns of a table that
uniquely identify a record in a database table. It is little like primary key but it
can accept only one null value and it cannot have duplicate values.

The unique key and primary key both provide a guarantee for uniqueness for a
column or a set of columns.

There is an automatically defined unique key constraint within a primary key


constraint.There may be many unique key constraints for one table, but only one
PRIMARY KEY constraint for one table.
LOGICAL OPERATORS
The Logical operators are those that are true or false. They return a true or
false values to combine one or more true or false values.

The Logical operators are:

Operator Description

AND Logical AND compares between two Booleans as expression and returns true when both
expressions are true...

OR Logical OR compares between two Booleans as expression and returns true when one of the
expression is true...

NOT Not takes a single Boolean as an argument and changes its value from false to true o
from true to false....
AND OPERATOR
Logical AND compares two Booleans as expression and returns TRUE when
both of the conditions are TRUE and returns FALSE when either is FALSE;
otherwise, returns UNKNOWN (an operator that has one or two NULL
expressions returns UNKNOWN).
OR OPERATORS
Logical OR compares two Booleans as expression and returns TRUE when
either of the conditions is TRUE and returns FALSE when both are FALSE.
otherwise, returns UNKNOWN (an operator that has one or two NULL
expressions returns UNKNOWN).
NOT OPERATORS
Logical NOT takes a single Boolean as an argument and changes its value
from false to true or from true to false.
COUNT() FUNCTION
The SQL COUNT() function returns the number of rows in a table satisfying
the criteria specified in the WHERE clause. It sets the number of rows or non
NULL column values.
COUNT() returns 0 if there were no matching rows.
AVG() FUNCTION
SQL AVG() function calculates the average value of a column of numeric type.
It returns the average of all non NULL values
SUM() FUNCTION
The SQL AGGREGATE SUM() function returns the SUM of all selected
column.
IN OPERATORS
The IN operator checks a value within a set of values separated by commas
and retrieve the rows from the table which are matching. The IN returns 1
when the search value present within the range otherwise returns 0.
BETWEEN OPERATORS
The SQL BETWEEN operator tests an expression against a range. The range
consists of a beginning, followed by an AND keyword and an end expression.
The operator returns TRUE when the search value present within the range
otherwise returns FALSE. The results are NULL if any of the range values are
NULL.
Group by Clause
The GROUP BY Statement in SQL is used to arrange identical data into groups with
the help of some functions. i.e if a particular column has same values in different
rows then it will arrange these rows in a group.
Important Points:
 GROUP BY clause is used with the SELECT statement.
 In the query, GROUP BY clause is placed after the WHERE clause.
 In the query, GROUP BY clause is placed before ORDER BY clause if used
any.
Order by Clause
The ORDER BY statement in sql is used to sort the fetched data in either ascending
or descending according to one or more columns.
 By default ORDER BY sorts the data in ascending order.
 We can use the keyword DESC to sort the data in descending order and the
keyword ASC to sort in ascending order.
Difference Between GROUP BY AND ORDER BY....
BASIS FOR
GROUP BY ORDER BY
COMPARISON

Basic Group By is used to form Order By is used to arrange

the Group of the set of the data obtained as a result of

the tuples. a query in Sorted form.

Attribute Attribute under Attribute under aggregate can

Aggregate function can be in Order By Clause.

not be in Group By

clause.

Ground Done on the ground of Done on the ground of

similarity among attribute ascending order and

values. descending order.


Having Clause and Where Clause
The HAVING clause was added to SQL because the WHERE keyword could
not be used with aggregate functions.

The WHERE clause is used to extract only those records that fulfill a specified
condition
JOIN CLAUSE
The SQL JOIN clause is used to combine records from two or more tables in a
database . A JOIN is a mean for combining fields from two tables by using
values common to each.
LEFT JOIN CLAUSE
he SQL LEFT JOIN (specified with the keywords LEFT JOIN and ON) joins
two tables and fetches all matching rows of two tables for which the SQL-
expression is true, plus rows from the frist table that do not match any row in
the second table.
RIGHT JOIN CLAUSE
The SQL RIGHT JOIN, joins two tables and fetches rows based on a
condition, which is matching in both the tables ( before and after the JOIN
clause mentioned in the syntax below) , and the unmatched rows will also be
available from the table written after the JOIN clause 

You might also like