Professional Documents
Culture Documents
2. ASSIGNMENT-1 7-9
CLASS TABLE
3. ASSIGNMENT-2 10-24
CUSTOMER TABLE
4. ASSIGNMENT-3 25-36
EMPLOYEE TABLE
5. ASSIGNMENT-4 37-49
EMPLOYEE123
2
SQL
Structured query language (SQL) is a programming language for storing and processing
information in a relational database. A relational database stores information in tabular form,
with rows and columns representing different data attributes and the various relationships
between the data values.
HISTORY
SQL has been around since the 1970s, and was standardized by the American National
Standards Institute (ANSI) in 1986. Since then, SQL has become the most widely used
language for managing relational databases and has undergone several revisions to keep pace
with the evolving needs of the database industry.
FEATURES
1. Data Definition Language (DDL): SQL provides a set of commands to define and modify
the structure of a database, including creating tables, modifying table structure, and
dropping tables.
2. Data Manipulation Language (DML): SQL provides a set of commands to manipulate
data within a database, including adding, modifying, and deleting data.
3. Query Language: SQL provides a rich set of commands for querying a database to
retrieve data, including the ability to filter, sort, group, and join data from multiple tables.
4. Transaction Control: SQL supports transaction processing, which allows users to group a
set of database operations into a single transaction that can be rolled back in case of
failure.
5. Data Integrity: SQL includes features to enforce data integrity, such as the ability to
specify constraints on the values that can be inserted or updated in a table, and to enforce
referential integrity between tables.
6. User Access Control: SQL provides mechanisms to control user access to a database,
including the ability to grant and revoke privileges to perform certain operations on the
database.
7. Portability: SQL is a standardized language, meaning that SQL code written for one
database management system can be used on another system with minimal modification.
3
SQL COMMANDS
Structured query language (SQL) commands are specific keywords or SQL statements that
developers use to
manipulate the data stored in a relational database. You can categorize SQL commands as
follows:
Data Definition Language
Data definition language (DDL) refers to SQL commands that design the database structure.
Database
engineers use DDL to create and modify database objects based on the business requirements.
For example,
the database engineer uses the CREATE command to create database objects such as tables,
views, and
indexes.
Data Query Language
Data query language (DQL) consists of instructions for retrieving data stored in relational
databases. Software
applications use the SELECT command to filter and return specific results from a SQL table.
Data Manipulation Language
Data manipulation language (DML) statements write new information or modify existing
records in a
relational database. For example, an application uses the INSERT command to store a new
record in the
database.
Data Control Language
Database administrators use data control language (DCL) to manage or authorize database
access for other
users. For example, they can use the GRANT command to permit certain applications to
manipulate one or
more tables.
Transaction Control Language
The relational engine uses transaction control language (TCL) to automatically make
database changes. For
4
example, the database uses the ROLLBACK command to undo an erroneous transaction.
DATA TYPES
Data types are used to represent the nature of the data that can be stored in the database table.
For
example, in a particular column of a table, if we want to store a string type of data then we
will
have to declare a string data type of this column.
Data types mainly classified into three categories for every database.
o String Data types
o Numeric Data types
o Date and time Data types
A list of data types used in SQL database:
1. Integer
Integer data types often represent whole numbers in programming. An integer value moves
from one integer to another without acknowledging fractional numbers in between. The
number of digits can vary based on the device, and some programming languages may allow
negative values.
2. Character
In coding, alphabet letters denote characters. Programmers might represent these data types
as (CHAR) or (VARCHAR), and they can be single characters or a string of letters.
Characters are usually fixed-length figures that default to 1 octet—an 8-bit unit of digital
information—but can increase to 65,000 octets.
3. Date
This data type stores a calendar date with other programming information. Dates are typically
a combination of integers or numerical figures. Since these are typically integer values, some
programs can store basic mathematical operations like days elapsed since certain events or
days away from an upcoming event.
4. Floating point (real)
Floating-point data types represent fractional numbers in programming. There are two main
floating-point data types, which vary depending on the number of allowable values in the
string:
Float: A data type that typically allows up to seven points after a decimal.
Double: A data type that allows up to 15 points after a decimal.
5
5. Long
Long data types are often 32- or 64-bit integers in code. Sometimes, these can represent
integers with 20 digits in either direction, positive or negative. Programmers use an
ampersand to indicate the data type is a long variable.
6. Short
Similar to the long data type, a short is a variable integer. Programmers represent these as
whole numbers, and they can be positive or negative. Sometimes a short data type is a single
integer.
7. String
A string data type is a combination of characters that can be either constant or variable. This
often incorporates a sequence of character data types that result in specific commands
depending on the programming language. Strings can include both upper and lowercase
letters, numbers and punctuation.
8. Boolean
Boolean data is what programmers use to show logic in code. Its typically one of two
values—true or false—intended to clarify conditional statements. These can be responses to
if/when scenarios, where code indicates if a user performs a certain action. When this
happens, the Boolean data directs the program response, which determines the next code in
the sequence.
9. Nothing
The nothing data type shows that a code has no value. This might indicate that a code is
missing, the programmer started the code incorrectly or that there were values that defy the
intended logic. Its also called the nullable type.
10. Void
Similar to the nothing type, the void type contains a value that the code cannot process. Void
data types tell a user that the code can return a response. Programmers might use or encounter
the void data type in early system testing when there are no responses programmed yet for
future steps.
6
ASSIGNMENT-1
desc studentm2;
7
CREATING NEW COLUMN
alter table studentm2 add contactnumber number(10);
desc studentm2;
8
INSERT VALUES
insert into studentm2 values(084,’Jasleen’,’Hari Nagar’,8552367845);
select*from studentm2
9
ASSIGNMENT-2
10
INSERT CUSTOMER VALUES
insert into customer values(101,’Dev’,’Verma’,’Delhi’,110027);
11
12
EXTRACT TABLE RECORDS
Select*from customer
13
DISPLAY FNAME,LNAME AND STATE
Select customerfname,customerlname,customerstate from customer;
14
DISPLAY FNAME,LNAME CONCATED WITH STATE
Select concat(customerfname,customerlname),customerstate from customer;
15
SELECT CUSTOMERSTATE FROM CUSTOMER
Select customerstate from customer;
16
DISPLAY RECORDS OF DELHI OR PUNJAB
Select*from customer where customerstate=’Delhi’ or customerstate=’Punjab’
17
DISPLAY DETAILS OF CUSTOMER EXCEPT CUSTOMERID 104
Select*from customer where customerid!=104
18
RETRIEVE ALL ROWS WHERE CID IS BETWEEN 102 AND 104
Select*from customer where customerid between 102 and 104;
19
RETRIEVE ALL ROWS WHERE FIRST NAME CONTAINS THE WORD ‘RAJ’
Select*from customer where customerfname like ’%Raj’;
20
RETRIEVE ALL ROWS WHERE STATE IS DELHI OR PUNJAB
Select*from customer where customerstate=’Delhi’ or customerstate=’Punjab’;
21
DELETE ALL THOSE ROWS OF CUSTOMERS WHO STAY IN KERALA
delete from cust where customerstate ‘Kerala’;
Select*from cust
22
DELETE THOSE CUSTOMERS WHO DO NOT HAVE PINCODE
delete from cust where customerpincode is null;
select*from cust
23
RENAME COLUMN STATE TO ADDRESS
alter table cust rename column customerstate to customeraddress
select*from cust;
24
DELETE THE CUSTOMERS WHO DO NOT BELONG TO DELHI
delete from cust where customeraddress not in(‘Delhi’)
select*from cust;
25
ASSIGNMENT-3
26
INSERT EMPLOYEE VALUES INTO EMPLOYEE TABLE
insert into employee1 values(1,’Ayush’,’Male’,’Dwarka’,1000000,1,’27-April-1999’)
27
EXTRACT THE TABLE RECORDS
Select*from employee1
28
DISPLAY EMPFNAME EMPLOYEE DEPARTMENT IS ‘5’
Select empfname from employee1 where empdepartment=5
29
SELECT EMPFNAME AND EMPLNAME WHERE EMPSALARY IS BETWEEN
30000 AND 50000
Select empfname,emplname,empsalary from employee1 where empsalary between 30000 and
50000
30
DISPLAY EMPFNAME AND EMPLNAME WHERE EMPGENDER IS ‘FEMALE’
Select empfname,emplname from employee1 where empgender=’Female’
31
DISPLAY EMPFNAME AND EMPLNAME WHERE EMPFNAME=AMIT’ AND
EMPLNAME=KUMAR’
select empfname,emplname from employee1 where empfname=’Amit’ and
emplname=’Kumar’
32
select*from employee1
33
UPDATE EMPFNAME TO ANKITA WHERE EMPFNAME IS ISHITA
update employee1 set empfname=’Ankita’ where empfname=’Ishita’
34
UPDATE EMPCITY TO JAIPUR WHERE EMPID IS 1
update employee1 set empcity=’Jaipur’ where empid=1;
select*from employee1
35
DELETE EMPLOYEE RECORD WHERE EMPID IS 2
delete from employee1 where empid=2;
36
DISPLAY EMPFNAME AND EMPLNAME WHERE EMPSALARY IS 30000
select empfname,emplname from employee where empsalary!=30000;
37
ASSIGNMENT-4
38
INSERT VALUES
insert into employee123 values(1,’Ayush’,’Dawar’,101,’Manager’,100000);
39
EXTRACT TABLE RECORDS
select*from employee123
40
DISPLAY AVERAGE EMPSALARY
select avg(empsalary) from employee123
41
DISPLAY MINIMUM OF EMPSALARY
select min(empsalary) from employee123
42
DISPLAY MAX OF EMPSALARY FROM THE DESIGNATION OF MANAGER
select max(empsalary) from employee123 where empdesignation=’Manager’
43
select empsalary+empsalary*50/100 from employee123
44
DISPLAY COUNT OF EMPID
select count(empid) from employee123
45
DISPLAY COUNT OF EMPLDEPARTMENT WHERE EMPDEPARTMENT IS 101
select count(empdepartment) from employee123 where empdepartment=’101’
46
select empfname,emplname,empsalary,empid,empdesignation from employee123 where
empsalary in(select min (empsalary) from employee123 where empdesignation=’Manager’)
47
select count(empid),avg(empsalary) from employee123 group by empdepartment having
count(empid)>0
48
select empdesignation,count(empdesignation) from employee123 group by empdesignation
49
select sum(empsalary),max(empsalary),min(empsalary),avg(empsalary) from employee123
where empdesignation =’Assistant’
50
51