Computer Science Practical
Computer Science Practical
A DBMS Serves as an interface between an End-User and a Database and allows users to:
Create a table
Insert, Update, and Delete records in a Database.
MERIT DEMERIT
Storing and Retrieval of Data Expensive Hardware
Sharing of data Scale and complexities
Integrity is Maintained High Storage
Data Security Significant impact on failure
Reducing Redundancy Frequent Updating required
Consistency Massive Dimensions
1
Views- is a virtual table that doesn’t exist its own.
Primary Key –It is an attribute of a table or a set of columns that helps to identify every record
present in that table uniquely. There can be only one primary key (i.e., the values in its domain will
be ATOMIC).
Candidate Key - Candidate keys are those attributes that uniquely identify rows of a table (There
are more than one Primary key).
Alternate Key - A table can have multiple choices for a primary key; however, it can choose only
one. So, all the keys which did not become the Primary Key are called Alternate keys.
Foreign Key - Foreign Key is used to establish relationships between two tables. A Foreign key
will require each value in a column or set of columns to match the Primary Key of the referential
table. Foreign keys help to maintain data and referential integrity.
2
Chapter 2
The Structured Query Language (SQL) is a language that enables us to create relational Databases
and Manipulate upon it using various processing capabilities.
Output:
Data Definition Language (DDL): DDL commands allow us to define a table and perform tasks
such as
CREATE
ALTER
DROP
DESC
3
1. Write a command to create and display a Table Employee inMYSQL.
Output:
3. Write a Command to add Columns Age and Hire Date in the Table
Employee.
Data Manipulation Language (DML): DML commands allow us to manipulate a table and perform
tasks such as
INSERT
UPDATE
DELETE record(s) in a table.
4
1. Write a command to insert a record with data into the table Employee
2. Write a command to select all rows from table Employee and table Department
Table: EMPLOYEE
Table: DEPARTMENT
Output:
5
4. Write a command to select names of employees that do not earn between 20000 and 50000.
Output:
5. Write a command to select entire row where name starts from letter ‘a’.
Output:
6. Write a
Output:
7. Write a command
Output
6
8. Write a command to update the table employee, set designation as CEO where Ename is ‘Kuldeep’
and then display the table.
Output:
9. Write a command to count the numbers of employees in every designation having less than 3
employees in each designation using group by command.
Output:
10. Write a command to delete all records and then uses select all command.
Transaction Control Language (TCL):Itis a subset of SQL used to manage database transactions.
2.2 Data Dictionary:is a file that contains “Metadata” i.e., “Data about Data”.
7
2.3 Scripting
There are two types of Scripting:
Server side Scripting: Where databases are processed and respond to the browser.
Client-side Scripting: Where browser can request server.
Logical Operator:
1. AND
8
2. OR
3. NOT
Chapter 3
Functions in MySQL
Functions are Sub-Programs that can be re-used throughout SQL database applications for
processing or manipulating of data.
a)String Functions
1. LENGTH ( ) 2. CONCAT ( )
Output: Output:
3. LOWER ( ) 4. LCASE ( )
Output: Output:
9
5. UPPER ( ) 6. UCASE ( )
10
Output:
Output:
7. INSTR ( ) 8. LEFT ( )
Output: Output:
Output: Output:
11. RTRIM ( )
Output:
Output: Output:
11
3. TRUNCATE ( ) 4. SQRT ( )
Output: Output:
5. FLOOR ( ) 6. MOD ( )
Output: Output:
c) Date/Week/Month/Year/Time Functions:
1. CURDATE ( ) 2. NOW ()
Output: Output:
3. SYSDATE ( ) 4. DATE ( )
12
Output: Output:
5. WEEK ( ) 6. DAY ( )
Output: Output:
7. MONTH ( ) 8. YEAR ( )
Output: Output:
Output: Output:
Output: Output:
13
13. MONTHNAME ( )
Output:
MAX( )
MIN( )
AVG( )
SUM( )
COUNT( )
Table Employee:
14
Commands and Aggregate Functions:
1. MAX( ): 2. MIN( ):
Output: Output:
3. AVG ( ): 4. SUM ( ):
Output: Output:
Output: Output:
15
Join Functions
Output:
Output:
16
17
c) Cartesian Product: Cartesian Product generates all possible combinations of
records from two given sets of data.
Output:
18
Chapter 4
Programming in Python
Output:
19
4.2 WAP to print elements of a tuple in separate lines.
Output:
4.4 WAP in python where you can use call by value(immutable) & call by reference(mutable).
21
Output:
4.6 WAP to get roll numbers, names and marks of the students.
23
Output:
24
Output:
4.8 WAP to read a text file and display the count of vowels& consonants.
25
Output:
4.9 WAP to write onto a binary file available in the form of dictionary.
26
Output:
27
Output:
28
Output:
4.12 WAP to create a binary file, write on it and display the string until letter ‘o’ is encountered.
29
Output:
4.13 WAP to open file stu.dat and search with roll numbers as 14.
30
Output:
31
4.14 WAP to update the records of file and display the modified records.
Output:
4.15 WAP to create a CSV file and write 6 records onto it.
32
Output:
4.16 WAP to create a CSV file by suppressing the EOL translation and display the content.
33
Output:
4.17 WAP to read a text file and count the number of lower and upper-case letters.
34
Output:
4.18 WAP to read the given details of sports performance and store into CSV file delimited with tab
character.
35
Output:
36
4.19 WAP that defines and calls user defined functions ADD ( ) and COUNTR ( ) the records
respectively.
Output:
37
4.20 WAP to accept string till the user enters “END” and displays only those sentences which begin
with an uppercase alphabet.
Output:
38
4.21 WAP to manage interface between MySQL & python using fetchone ( ).
Output:
39
4.22 WAP to manage interface between MySQL & python using fetchmany ( ).
Output:
40
4.23 WAP to manage interface between MySQL & python using fetchall ( ).
Output:
41