Database 2
Database 2
BRANCH : - INFORMATION
TECHNOLOGY
SUBJECT : - DBMS
SEMESTER : - 4th
SUBMITTED TO SUBMITTED BY
ANURADHA
Ma’am
1
H
INDEX
2.
Write SQL command Such as insertion , deletion,
updation for any schema…
2
H
DROP
Syntax
DROP TABLE table_name;
Syntax
TRUNCATE TABLE table_name;
Truncate Table Persons ;
ALTER
Syntax
3
H
Comments
--Select all:
SELECT * FROM Customers;
RENAME
INSERT
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
4
H
DELETE
DELETE FROM table_name WHERE condition;
UPDATE
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
UPDATE Student
SET Name = 'Pankaj'
WHERE StudID = '101';
Grant privilageName
on objectName
To{userName/Public/roleName}
[with Grant Option]
REVOKE
REVOKE privilege_name
ON object_name
FROM {user_name |PUBLIC |role_name}
5
H
Q 2 }Write SQL command Such as insertion , deletion, updation for any schema…
INSERTION
DELETION
DELETE FROM table_name WHERE condition;
UPDATION
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
UPDATE Student
SET Name = 'Pankaj'
WHERE StudID = '101';
6
H
Q 3 } To Execute Nested Queries, Join Queries , Order by , Having clause , and string
Operation
Nested Queries
ANY Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name operator ANY
(SELECT column_name
FROM table_name
WHERE condition);
SELECT ProductName
FROM Products
WHERE ProductID = ANY
(SELECT ProductID
FROM OrderDetails
WHERE Quantity = 10);
Join Queries
INNER JOIN Syntax
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;
SELECT Orders.OrderID,
Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID =
Customers.CustomerID;
7
H
SELECT Customers.CustomerName,
Orders.OrderID
FROM Customers
LEFT JOIN Orders ON Customers.CustomerID =
Orders.CustomerID
ORDER BY Customers.CustomerName;
ORDER BY Syntax
SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;
SELECT * FROM Customers
ORDER BY Country;
HAVING Syntax
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5;
String Function
9
H
Intersect Syntax
SELECT column1, column2,…, columnN
FROM table1, table2,…, tableN
INTERSECT
SELECT column1, column2,…, columnN
FROM table1, table2,…, tableN
SQL> SELECT NAME, AGE, HOBBY FROM STUDENTS
INTERSECT
SELECT NAME, AGE, HOBBY FROM ASSOCIATES
Minus syntax
SELECT expression1, expression2, ... expression_n
FROM tables
[WHERE conditions]
MINUS
SELECT expression1, expression2, ... expression_n
FROM tables
[WHERE conditions];
10
H
Q5 } To Execute various Commands for GROUP function (avg, count, max, min , sum)
GROUP BY Syntax
SELECT column1, column2, ...
FROM table
GROUP BY columnA, columnB, ...;
Count function ()
SELECT country, COUNT(*) AS number
FROM Customers
GROUP BY country;
Sum function()
SELECT SUM(column_name)
FROM table;
SELECT SUM(amount) AS total_sales
FROM Orders;
Avg function()
SELECT AVG(column_name)
FROM table;
SELECT AVG(age) AS average_age
FROM Customers;
Max function()
SELECT MAX(columnn)
FROM table;
SELECT MAX(age)
FROM Customers;
Min function()
SELECT MIN(columnn)
FROM table;
SELECT MIN(age)
FROM Customers;
11
H
PL/SQL stands for Procedural Language extensions to the Structured Query Language
(SQL).
2].
UPDATE customers
SET salary = salary + 500
WHERE id = 2;
OUTPUT:-
Old salary: 1500
New salary: 2000
Salary difference: 500
12
H
RETURN total;
END;
/
Function created.
DECLARE
c number(2);
BEGIN
c := totalCustomers();
dbms_output.put_line('Total no. of Customers: ' || c);
END;
/
OUTPUT :-
In an information system, input is the raw data that is processed to produce output. During the input
design, the developers must consider the input devices such as PC, MICR, OMR, etc.
Therefore, the quality of system input determines the quality of system output. Welldesigned input
forms and screens have following properties −
• It should serve specific purpose effectively such as storing, recording, and retrieving the
information.
• It ensures proper completion with accuracy.
• It should be easy to fill and straightforward.
• It should focus on user’s attention, consistency, and simplicity.
Objectives for Input Design
The objectives of input design are −
• To design data entry and input procedures
• To reduce input volume
• To design source documents for data capture or devise other data capture methods
• To design input data records, data entry screens, user interface screens, etc.
• To use validation checks and develop effective input controls.
Forms Design
Both forms and reports are the product of input and output design and are business document
consisting of specified data. The main difference is that forms provide fields for data input but reports
are purely used for reading. For example, order forms, employment and credit application, etc.
• During form designing, the designers should know −
14
H
15
H
Q 9}: Create reports using database connectivity of Front end with back end.
A client or front-end database application also interacts with the database by requesting and
receiving information from database server. It acts as an interface between the user and the
database.
The database server or back end is used to manage the database tables and also respond to client
requests.
A front-end or a client portion The client executes the database application that accesses database
information and interacts with the user.
A back-end or a server portion The server executes the MySql and handles the functions required
for concurrent, shared data access to MySql database.
Database Connectivity using C/C++
return 0;
Create reports using database
In order to use MySQL you will need to have the MySQL Connector/ODBC driver installed on
the system where the OAS Engine is running.
If it is not currently installed you can download from
here: https://downloads.mysql.com/archives/c-odbc/
In order to use the ODBC Administrator you may also need to install the Visual C++
Redistributable for Visual Studio x86.
In MySQL create a separate user from root. You will uses this user in the string below.
Database = DatatBaseName
Table = a table within the database.
Dataset should now show table elements
17
H
Q10} create database design with normalization and implementing in any applications ..
[PhoneNumber] VARCHAR(12),
[Address] VARCHAR(255),
[City] VARCHAR(255),
[Zip] VARCHAR(5)
)
20