Dbmslab
Dbmslab
SQL (Structured Query Language) is a standard programming language for managing and manipulating
relational databases
10 uses of SQL
There are a variety of uses of SQL, although the frequency of these uses may change based on your
specific career. For example, data scientists and web development professionals both use this language,
yet they use it for different purposes. You can use SQL to:
If you access a database that has organized data within a table, you can use SQL to manipulate this data.
For example, you can change certain data points within the table. Additionally, you could alter every
section of the table with updated data. This is a very common use of SQL.
2. Create a table
Another use of SQL is the ability to create a new table. Users may create a brand new database by adding
new data into a table once it's created. This function allows users to contribute data to the system, which
can further analyze, manipulate and store it.
3. Retrieve data
Many data scientists can use SQL to retrieve data from within the database. The process for this in SQL is
DQL, which stands for Data Query Language. After retrieving the data, it's easier to analyze and assess
it. The syntax for this command is "SELECT."
Another use of SQL is to change the structure of the data. You can do this by changing the database or
table where the data's stored. A professional may use SQL for this purpose if there's new data that makes
the current storage process outdated.
You can use SQL to define your database's schema, which contributes to data descriptions and
structuring. The name of this process is data definition language, or DDL. The commands you can use for
this process include "CREATE," "DROP," "ALTER," "TRUNCATE," "COMMENT" and "RENAME."
You can use the DML, or data manipulation language, feature to store, modify, delete or update the data.
You might use SQL for this purpose if you want to refresh the whole database to ensure it's accurate and
updated. The commands for this include "INSERT," "UPDATE" and "DELETE." Here's an example of
how to use these commands:
1
7. Grant access to data
If you manage the database, you can provide access to other users using SQL. The method for this is
DCL, which means data control language. You can use the commands "GRANT" and "REVOKE" to
determine which users have access to which databases within the program. This use may benefit
businesses that store confidential or sensitive data within the program.
Using SQL, you can add functions and procedures based on your specific database needs. For example,
you can link simple SQL syntax to a specific command before you begin using the system. This helps you
meet the requirements for your business and simplifies the process of using the language.
You can use SQL to manually analyze the data within your system. This may be necessary when you
need to intervene with the system manually. While troubleshooting or solving an issue with the database,
manual analysis can provide an alternative way to continue accessing the data. Users can use SQL queries
to search for necessary data, which they can then use for analysis.
The SQL Join function allows users to combine data from two sets. You might use this feature if you
want to combine and compare two different tables. You can use the following commands:
(INNER) JOIN: This command can show the programmer if any outputs in the two systems are
overlapping. For example, if there are multiple outputs classified as "REVIEW," this function shows each
of these outputs.
LEFT (OUTER) JOIN: This command shows the user every aspect of the left-hand table, and compares it
to the outputs of the other table.
RIGHT (OUTER) JOIN: This command shows the user every aspect of the right-hand table. Then, it
compares these aspects with the outputs of the left-hand table.
FULL (OUTER) JOIN: This method completely joins the two tables together. It can show a user all the
areas where data matches between the two tables.
History
SQL was first developed in the early 1970s at IBM by a team led by Donald D. Chamberlin and Raymond
F. Boyce. The original name of the language was SEQUEL, which stood for "Structured English Query
Language." SEQUEL was designed to be a simple and intuitive way to access and manipulate data
stored in IBM's System relational database management system. SEQUEL was later renamed to SQL,
and IBM released the first commercial implementation of the language in 1981 as part of their System
2
relational database management system (RDBMS).
SQL quickly became the standard language for interacting with relational databases, and it was soon
adopted by other RDBMS vendors such as Oracle, Sybase, and Microsoft. SQL also saw the emergence
of several popular open-source implementations of the language, such as MySQL and PostgreSQL.
Oracle and Microsoft's implementations and commercial offerings are widely used today.
Q2 Discuss the DBMS languages and elaborate it with its data types
1. Data Definition Language (DDL)
DDL stands for Data Definition Language. It is used to define database structure or pattern.
Using the DDL statements, you can create the skeleton of the database.
Data definition language is used to store the information of metadata like the number of tables and
schemas, their names, indexes, columns in each table, constraints, etc.
These commands are used to update the database schema that's why they come under Data definition
language.
DML stands for Data Manipulation Language. It is used for accessing and manipulating data in a
database. It handles user requests.
3
Select: It is used to retrieve data from a database.
DCL stands for Data Control Language. It is used to retrieve the stored or saved data.
(But in Oracle database, the execution of data control language does not have the feature of rolling back.)
There are the following operations which have the authorization of Revoke:
TCL is used to run the changes made by the DML statement. TCL can be grouped into a logical
transaction.
Rollback: It is used to restore the database to original since the last Commit.
4
Data types in SQL Server are organized into the following categories:
float - Floating precision number data from -1.79E + 308 to 1.79E + 308.
5
nvarchar(max) - Variable width Unicode string
6
EXPERIMENT-1
Objective- to create,select, insert and display the values in a database.
Create Command
7
Insert Command
Select Command
Syntax- Select* from table_name
8
EXPERIMENT-2
Objective- to add,modify,drop and display the values in a database.
Alter(add) Command
Syntax- ALTER TABLE table_name ADD column_name datatype;
9
Alter(modify)
Synatx-ALTER TABLE table_name MODIFY COLUMN column_name datatype;
Alter(drop) Command
Syntax-ALTER TABLE table_name DROP COLUMN column_name;
10
EXPERIMENT-3
Objective- to update,delete,Distinct and display the values in a database
Update Command
Syntax- UPDATE table_name SET [column_name1= value1,... column_nameN =
vaueN] [WHERE condition]
Delete Command
Syntax- DELETE FROM table_name [WHERE condition];DELETE FROM table_name
11
Distinct Command
Syntax-SELECT DISTINCT expressions FROM tables [WHERE conditions];
12
EXPERIMENT-4
Objective- to use and,or,not and display the values in a database
And Command
Syntax-SELECT column1, column2,..FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;
13
NOT Command
Synatx-SELECT column1, column2,FROM table_name
WHERE NOT condition;
14
EXPERIMENT-5
Objective- to use orderby and display the values in a database
15
Orderby Command
Syntax-SELECTcolumn1, column2,FROM table_name ORDER BY column1,
column2, ... ASC|DESC;
EXPERIMENT-6
Objective- to use SQL Functions and display the values in a database
16
Maximum Command
Syntax- Select max(columnname)from table_name
Minimum Command
Syntax- Select min(columnname)from table_name
17
Count Command
Syntax- Select count(columnname)from table_name
18
Average Command
Syntax- Select avg(columnname)from table_name
Sum Command
Syntax- Select sum(columnname)from table_name
19
EXPERIMENT-7
Objective- to use LIKE Functions and display the values in a database
Syntax- Select* from table_name where(columnname)like’a%’
20
21
Syntax- Select* from table_name where(columnname)like’%l’
22
Syntax- Select* from table_name where(columnname)like’_u%’
24
EXPERIMENT-8
Objective- Create a table for a customer who orders products from different
countries. Find the
25
a) the distinct value
26
b)values where the customer orders from Europe, Mexico countries
27
f)the customer ordered from Germany but not from Mexico
28
g)the customer orders from different countries display the result n ascending
order of different countries
29
EXPERIMENT-9
Objective- to use JOIN Functions and display the values in a database
Syntax- SELECT * FROM TABLE1 INNER JOIN TABLE2 ON
TABLE1.COLUMNNAME=TABLE.COLUMNNAME
30
Syntax- SELECT COLUMNNAME FROM TABLE1 FULL OUTER JOIN TABLE2 ON
TABLE1.COLUMNNAME=TABLE2.COLUMNNAME
31
EXPERIMENT-10
Objective- to use ALIASES Functions and display the values in a database
Syntax- SELECT COLUMNNAME AS C_NAME FROM TABLENAME
32
EXPERIMENT-11
Objective- to use UNION OPERATOR Functions and display the values in a
database
33
Syntax- SELECT COLUMNANME FROM TABLE1 MINUS SELECT COLUMNNAME
FROM TABLE2
34
EXPERIMENT-12
Objective - Write a query in SQL to display the last name and job tle of all
employees who do not have a manager
EXPERIMENT-13
Objective- Write a query in SQL to display the last name, salary, and
commission of all employees who earn commissions. Sort data in descending order
of salary and commissions
35
36
EXPERIMENT-14
Objective- Write a query in SQL that prompts the user for a manager ID and
generates the employee ID, last name, salary, and department for that manager’s
employees. The HR department wants the ability to sort the report on a selected
column
37
EXPERIMENT-15
Objective- Write a query in SQL to Display all employee last names in
which the third le er of the name is a.
38
EXPERIMENT-16
Objective- Write a query in SQL to Display the last name of all employees who
have both an a and an e in their last name.
39
EXPERIMENT-17
Objective- Write a query in SQL to Display the last name, job, and salary for all
employees whose job is sales representa ve or stock clerk and whose salary is not
equal to $2,500, $3,500, or $7,000.
40
EXPERIMENT-18
Objective- Write a query in SQL to display the employee number, last name,
salary, and salary increased by 15.5% (expressed as a whole number) for each
employee. Label the column New Salary.
41
EXPERIMENT-19
Objective- Create a report that produces the following for each
employee: <employee last name> earns <salary> monthly but wants <3
times salary>. Label the column Dream Salaries.
42
EXPERIMENT-20
Objective- Create a query to display the last name and salary for all
employees. Format the salary to be 15 characters long, left-padded with the $
symbol. Label the column SALARY
43
EXPERIMENT-21
Objective- Display each employee’s last name, hire date, and salary
review date, which is the first Monday after six months of service. Label the
column REVIEW. Format the dates to appear in the format similar to
“Monday, the Thirty-First of July, 2000.”
44
EXPERIMENT-22
Objective- Display the last name, hire date, and day of the week on
which the employee started. Label the column DAY. Order the results by the day
of the week, starting with Monday.
45
46
EXPERIMENT-23
Objective- WRITE A QUERY IN PLISQL TO PRINT 'HELLO WORLD'
SYNTAX: DECLARE message
World!'; BEGIN
DBMS OUTPUT.PUT LINE(message);
END;
47
EXPERIMENT-24
Objective- write a query in pl/sql to find the sum of two
variables
48
EXPERIMENT-25
Objective- write a query in pl/sql to demonstrate the use of
comments
SYNTAX: DECLARE
— variable declaration
Message 'Demonstration of comments'; BEGIN
49
EXPERIMENT-26
Objective- write a query in pl/sql to take input from the
user end.
SYNTAX:i integer;
j integer; s
integer; begin
50
EXPERIMENT-27
Objective- write a query in pl/sql for the use of loops
SYNTAX:DEcLARE
VARI NUMBER;
BEGIN
51
EXPERIMENT-28
Objective- write a query to demonstrate the use of if-else
statement.
SYNTAX:DECLARE
Marks 55;
BEGIN
52
EXPERIMENT-29
Objective- Execute the program in plSQL to calculate sum, multiplication of 3
numbers
DECLARE
num1 NUMBER := 10; -- Example value for the first variable
num2 NUMBER := 20; -- Example value for the second variable
num3 NUMBER := 30; -- Example value for the third variable
add NUMBER;
product NUMBER;
BEGIN
add := num1 + num2 + num3;
product := num1 * num2 * num3;
DBMS_OUTPUT.PUT_LINE('The sum of ' || num1 || ' , ' || num2 || ' and ' ||
num3 || ' is: ' || add);
DBMS_OUTPUT.PUT_LINE('The product of ' || num1 || ' , ' || num2 || ' and
' || num3 || ' is: ' || product);
53
EXPERIMENT-30
Objective- Execute the program in pl SQL to swap the 2
variables.
DECLARE
num1 NUMBER := 10; -- Example value for the first variable
num2 NUMBER := 20; -- Example value for the second variable
BEGIN
DBMS_OUTPUT.PUT_LINE('Before Swapping: Num 1 = ' || num1 || ' and
Num 2 = ' || num2);
num1 := num1 + num2;
num2 := num1 - num2;
num1 := num1 - num2;
DBMS_OUTPUT.PUT_LINE('After Swapping: Num 1 = ' || num1 || ' and Num
2 = ' || num2);
END;
54
55