Brief Notes For SQL-grade - 11
Brief Notes For SQL-grade - 11
relational database management systems such as MySQL, ORACLE, SQL Server, etc
b) The benefit with SQL is that we don’t have to specify how to get the data from the database.
Rather, we simply specify what is to be retrieved, and SQL does the rest
c) SQL can do much more besides querying. SQL provides statements for defining the structure
of the data, manipulating data in the database, declare constraints and retrieve data from
the database in various ways, depending on our requirements.
d) We know that a database consists of one or more relations and each relation (table) is made
up of attributes (column). Each attribute has a data type. We can also specify constraints for
each attribute of a relation.
e) Data type indicates the type of data value that an attribute can have.
f) Commonly used data types in MySQL are numeric types, date and time types, and string
(character and byte) types->
String : char() and varchar()
Numeric-int,float
Date and time-date
g) Constraints are certain types of restrictions on the data values that an attribute can have.
They are used to ensure the accuracy and reliability of data.
h) Which two constraints when applied together will produce a Primary Key constraint?
ans:
i)
j) DDL:SQL provides commands for defining the relation schemas, modifying relation schemas
and deleting relations. These are called Data Definition Language (DDL) .
Data definition starts with the create statement. This statement is used to create a database
and its tables (relations).
K) To create a database, we use the CREATE DATABASE statement as shown in the following
L) A DBMS can manage multiple databases on one computer. Therefore, we need to select the
database that we want to use. Once the database is selected, we can proceed with creating tables or
querying data.
K) Show tables command that lists names of all the tables within a database.
L) By default, each attribute can take NULL values except for the primary key
M) supposing the school uses guardian’s 12 digit Aadhaar number as GUID, we can declare GUID as
CHAR(12) since Aadhaar number is of fixed length and we are not going to perform any
mathematical operation on GUID.
O) DESCRIBE Table We can view the structure of an already created table using the describe
statement. Syntax:
DESCRIBE tablename.
MySQL also supports the short form DESC of DESCRIBE to get description of table.
R)
Note: We have to specify the data type of the attribute along with constraint NOT NULL while using
MODIFY
u) DROP Statement: DROP statement to remove a database or a table permanently from the system.
Data Manipulation using a database means either retrieval (access) of existing data, insertion of new
data, removal of existing data or modification of existing data in the database.
INSERTION of Records:
Note:
The user enters the SQL commands called queries
SELECT Statement: The SQL statement SELECT is used to retrieve data from the tables in a database
and the output is also displayed in tabular form.
Syntax:
SELECT attribute1, attribute2, ... FROM table_name WHERE condition
z) Renaming of columns: In case we want to rename any column while displaying the output, we
can do so by using alias 'AS' in the query as:
A1) DISTINCT Clause: The SELECT statement when combined with DISTINCT clause, returns records
without repetition (distinct records).
DISTINCT clause is used to eliminate repetition and display the values only once.
The WHERE clause is used to retrieve data that meet some specified conditions.
Note: We can also use other relational operators (<=, >, >=, !=) to specify conditions. The logical
operators AND, OR, and NOT are used with WHERE clause to combine multiple conditions.
MEMBERSHIP OPERATOR IN: The IN operator compares a value with a set of values and returns true
if the value belongs to that set.
The IN operator selects values that match any value in the given list of
values.
A3)ORDER BY: ORDER BY clause is used to display the result of an SQL query in ascending or
descending order with respect to specified attribute values. The default is ascending order.
A4) NULL Values: SQL supports a special value called NULL to represent a missing or unknown value.
It is important to note that NULL is different from 0 (zero). Also, any arithmetic operation performed
with NULL value gives NULL. For example: 5 + NULL = NULL because NULL is unknown hence the result
is also unknown
A5) LIKE :SQL provides LIKE operator that can be used with WHERE clause to search for a specified
pattern in a column.
mysql> SELECT * -> FROM EMPLOYEE -> WHERE Ename LIKE 'K%'
A6) UPDATE: The UPDATE statement is used to make such modifications in the existing data.
The DELETE statement is used to delete one or more record(s) from a table.