0% found this document useful (0 votes)
52 views

Brief Notes For SQL-grade - 11

SQL is the most popular query language used by major relational database management systems. It allows users to specify what data to retrieve from the database without specifying how to retrieve it. SQL can define data structure, manipulate data, and retrieve data in various ways depending on user requirements. Primary keys enforce uniqueness of records in a table and are defined by applying the UNIQUE and NOT NULL constraints together to a column or set of columns.

Uploaded by

BLUE SKY GAMING
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Brief Notes For SQL-grade - 11

SQL is the most popular query language used by major relational database management systems. It allows users to specify what data to retrieve from the database without specifying how to retrieve it. SQL can define data structure, manipulate data, and retrieve data in various ways depending on user requirements. Primary keys enforce uniqueness of records in a table and are defined by applying the UNIQUE and NOT NULL constraints together to a column or set of columns.

Uploaded by

BLUE SKY GAMING
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

a) The Structured Query Language (SQL) is the most popular query language used by major

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

syntax: CREATE DATABASE databasename;

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.

mysql> SHOW TABLES;

Empty set (0.06 sec)

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.

P) (A) Add primary key to a relation


Q) Add primary key to the ATTENDANCE relation. The primary key of this relation is a composite key
made up of two attributes — AttendanceDate and RollNumber.

R)

o) Add constraint UNIQUE to an existing attribute:

UNIQUE which means no two values in that column should be same.

p) ) Add an attribute to an existing table:

q) Modify datatype of an attribute:

r) Modify constraint of an attribute add not null)

Note: We have to specify the data type of the attribute along with constraint NOT NULL while using
MODIFY

s) Add default value to an attribute:


t) Remove an attribute:

u) Remove primary key from the table:

ALTER TABLE table_name DROP PRIMARY KEY;

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:

mysql> SELECT EName AS Name

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.

A2) Where: The WHERE clause is used to enforce condition(s) in a query.

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.

NULL values can be tested using IS NULL and IS NOT NULL.

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.

• % (percent)— used to represent zero, one, or multiple characters

• _ (underscore)— used to represent a single character

mysql> SELECT * -> FROM EMPLOYEE -> WHERE Ename LIKE 'K%'
A6) UPDATE: The UPDATE statement is used to make such modifications in the existing data.

UPDATE statement is used to modify existing data in a table.

A7) DELETE statement is used to delete records in a table.

The DELETE statement is used to delete one or more record(s) from a table.

Syntax: DELETE FROM table_name WHERE condition

You might also like