0% found this document useful (0 votes)
66 views41 pages

Computer Science Practical

The document discusses Database Management Systems (DBMS) and Relational Database Management Systems (RDBMS). It explains that a DBMS is software used to store, retrieve, and run queries on data. An RDBMS uses a table structure with rows and columns and includes functions. The document also covers structured query language (SQL), data definition language (DDL) and data manipulation language (DML) commands, functions in MySQL, and join functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views41 pages

Computer Science Practical

The document discusses Database Management Systems (DBMS) and Relational Database Management Systems (RDBMS). It explains that a DBMS is software used to store, retrieve, and run queries on data. An RDBMS uses a table structure with rows and columns and includes functions. The document also covers structured query language (SQL), data definition language (DDL) and data manipulation language (DML) commands, functions in MySQL, and join functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 41

Chapter 1

Database Management System (DBMS)


Database Management Systems (DBMS) is Software used to:
 Store
 Retrieve
 Run Queries on Data

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.

1.1 Advantages and Disadvantages of DBMS

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.2 Relational Database Management System (RDBMS)


An RDBMS consists of rows& column based Table Structure includes Functions.

Paid RDBMS Open-Source RDBMS


1.Microsoft Server 1.MySQL
2.IBM DB2 2.PostgreSQL
3.IBM Informix 3. SQLite
4.Sap Sybase
5.Teradata

TERM USED IN RDBMS

 Domain-is a unique set of values permitted for an attribute in a table.


 Tuple- refers to as a row or record in a table.
 Attributes- refers to as a field or a column in a table.
 Degree-represents the number of attributes in a table.
 Cardinality-represents the number of tuples in a table.

1
 Views- is a virtual table that doesn’t exist its own.

1.3 Keys And Constraints in RDBMS

 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

Structured Query Language (SQL)

The Structured Query Language (SQL) is a language that enables us to create relational Databases
and Manipulate upon it using various processing capabilities.

CREATE, SHOW and USE a DATABASE:


a) Command to Create a Database.

b) Command to Show a Database

Output:

c) Command to Use a Database.

2.1 Types of Query Languages


The SQL statements have been classified into its various forms but we shall discuss and use only
DDL and DML commands:

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.

2. Write a DDL command to describe (DESC) the table Employee.

Output:

3. Write a Command to add Columns Age and Hire Date in the Table
Employee.

4. Write a command to replace the data type of ECODE into Varcharwith


size 10.

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

3. Write a command to select distinct designation.

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.

2.4 Data Types and Operators


MySQL provide various data types:

 int: It is a normal-sized integer data type that can be signed or unsigned.


 float (n, d):A floating-point number is unsigned where n is the length and d representing the
number of decimals precision.
 char (n): It is used to store character strings of fixed length.
 varchar (n): It is used to store character strings of variable length.
 Date: Specifies the date in a program with format YYYY-MM-DD.

MySQL provide various Operators:

Relational Operator: Arithmetic Operator: Membership Operator:

1. <(Less than) 1. + (Add) 1. IN


2. > (Greater than) 2. – (Subtract) 2. NOT IN
3. = (Equals to) 3. * (Multiply) 3. BETWEEN
4. <= (Less than equal to) 4. / (Divide) 4. NOT BETWEEN
5. >= (Greater than equal to)
5. % (Mod) 5. LIKE
6. <> (Not equal to)
6. NOT LIKE

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.

3.1 Single Row Functions:return one output per row.

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:

9. RIGHT ( ) 10. LTRIM ( )

Output: Output:

11. RTRIM ( )

Output:

b) Mathematical/ Numeric Functions:

1. POWER ( ) / POW ( ) 2. ROUND ( )

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:

9. DAYOFWEEK ( ) 10. DAYOFMONTH ( )

Output: Output:

11. DAYOFYEAR ( ) 12. DAYNAME ( )

Output: Output:
13
13. MONTHNAME ( )

Output:

3.2 Multiple Row Functions


Multiple Row Functions Work upon Group of Rows and Return One Result for the Complete Set of
Rows.

3.3 Aggregate Functions

 MAX( )
 MIN( )
 AVG( )
 SUM( )
 COUNT( )

Table Employee:

14
Commands and Aggregate Functions:

1. MAX( ): 2. MIN( ):

Output: Output:

3. AVG ( ): 4. SUM ( ):

Output: Output:

5. COUNT (*): 6. COUNT DISTINCT ( ):

Output: Output:

15
Join Functions

a) Natural Join: in which only one of the identical columns exist.

Output:

b) Equi-Join: in which columns are compared for equality.

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

4.1 WAP to create and traverse a 2D list.

Output:

19
4.2 WAP to print elements of a tuple in separate lines.

Output:

4.3 WAP to create dictionary containing names.


20
Output:

4.4 WAP in python where you can use call by value(immutable) & call by reference(mutable).
21
Output:

4.5 WAP to display the Scope of Variables.


22
Output:

4.6 WAP to get roll numbers, names and marks of the students.

23
Output:

4.7 WAP to read a text files line by line.

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:

4.10 WAP to append student records.

27
Output:

4.11 WAP to open read and display a binary file.

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

You might also like