0% found this document useful (0 votes)
12 views5 pages

Database

The document provides an overview of database concepts and SQL, detailing the structure and management of databases through Database Management Systems (DBMS). It explains key components such as tables, relations, domains, tuples, and various types of keys, as well as the use of Structured Query Language (SQL) for data manipulation and definition. Additionally, it covers data types, advantages of SQL, and the concept of Cartesian products in relation to SQL joins.

Uploaded by

thunderbird3072
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)
12 views5 pages

Database

The document provides an overview of database concepts and SQL, detailing the structure and management of databases through Database Management Systems (DBMS). It explains key components such as tables, relations, domains, tuples, and various types of keys, as well as the use of Structured Query Language (SQL) for data manipulation and definition. Additionally, it covers data types, advantages of SQL, and the concept of Cartesian products in relation to SQL joins.

Uploaded by

thunderbird3072
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/ 5

Database Concepts and SQL

1 Database is a collection of related information that is organized in such a way that supports for easy
access, modify and maintain data.
2 The database is managed by some special software packages known as Database Management Systems
(DBMS)
DBMSs are specially designed applications to create connection between user and program, and to store
data in an organized manner.
The purpose of DBMSs software is to allow the user to create, modify and administration of database.
3 Examples of database management systems are: Ms-Access, MySQL, PostgreSQL, SQLite, Microsoft SQL
Server, Oracle, SAP, dBASE, FoxPro, etc.
4 Relational data model
In the relational data model, database is represented as collection of related tables.
Each table is termed as relation
Tables are formed by using rows and columns.
A row (horizontal subset) of a table represents a tuple or record,
A column (vertical subset) of a table represents an attribute.
5 Relation
In database, a relation means a 'table', in which data are organized in the form of rows and columns.
Therefore in database, relations are equivalent to tables.
6 A domain is the original sets of atomic values used to model data.
In data base management and database, a domain refers to all the possible unique values of a particular
column.
For example:
i) The domain of gender column has a set of two possible values i.e, Male or Female.
ii) The domain of marital status has a set of four possible values i.e, Married, Unmarried, Widows
and Divorced.
Therefore, a domain is a set of acceptable values of a particular column, which is based on various
properties and data types
7 Tuple
Horizontal subset/information in a table is called tuple. The tuple is also known as a 'record', row which
gives particular information of the relation (table).
For example: i) In customer table, one row gives information about one customer only.
ii) In student table, one row gives information about one student only.
8 The degree is the number of attributes (columns) in a table.
9 Cardinality is number of rows (tuples) in a table.
1 Keys are an important part of a relational database and a vital part of the structure of a table. They help
0 enforce integrity and help identify the relationship between tables.
There are three main types of keys - candidate keys, primary keys, foreign keys and alternate keys.
1 Primary Key: A column or set of columns that uniquely identifies a row within a table is called primary
1 key.
1 Candidate Key: Candidate keys are set of fields (columns with unique values) in the relation that are
2 eligible to act as a primary key.
1 Alternate Key: Out of the candidate keys, after selecting a key as primary key, the remaining keys are
3 called alternate key.
1 Foreign Key: A foreign key is a field (or collection of fields) in one table that uniquely identifies a row of
4 another table. In other words, a foreign key is a column or a combination of columns that is used to
establish a link between two tables.
Explain the use of ‘Foreign Key’ in a Relational Database Management System. Give example to support your answer.
Ans: A foreign key is used to set or represent a relationship between two relations ( or tables) in a database. Its value is derived from
the primary key attribute of another relation.
For example: In the tables TRAINER and COURSE given below,
TID is primary key in TRAINER table but foreign key in COURSE table.
TRAINER
TID TNAME CITY HIREDATE SALARY
101 Ritu Nagpur 1998-10-15 56700
102 Navin Goa 1994-12-24 80000
103 Murugan Chandigarh 2001-12-21 82000
104 Jyothi Guwahati 2002-12-25 68000
105 Chanu Mumbai 1996-01-12 95000
106 Arbaaz Delhi 2001-12-12 69000

COURSE

1|Page
Database Concepts and SQL

CID CNAME FEES STARTDATE TID


C201 Deepa 12000 2018-07-02 101
C202 Sindhu 15000 2018-07-15 103
C203 Neeraj 10000 2018-10-01 102
C204 Prakash 9000 2018-09-15 104
C205 Nikhat 20000 2018-08-01 101
1
5

Fields (Attributes/Columns):- AdNo, Name, Class, Section and Average.


Tuples (Rows/Records): 101 Anu 12 A 85
Domain: Possible values of section are ('A','B','C','D')
Degree: 5 (Number of columns).
Cardinality: 6 (Number of rows).
Candidate Key: In the above table, AdNo and Name has unique values. Therefore, AdNo and Name are
candidate keys.
Primary Key: Out of the AdNo and Name, AdNo is the primary key.
Alternate Key: In the candidate key, AdNo is the primary key and the Name is the Alternate key.
1 Structured Query Language (SQL)
6 Structured Query Language (SQL) is a standard language used for accessing databases.
This is a special purpose programming language used to create a table, manage data and mainipulate data
1 Advantages of using SQL:
7 1) SQL is portable:
2) High speed:
3) Easy to learn and understand
4) SQL is used with any DBMS system with any vendor
5) SQL is used for relational databases
1 Types of SQL Statements
8 The SQL statements are categorized into different categories based upon the purpose. They are;
i) Data Definition Language (DDL) statement
ii) Data Manipulation Language (DML) statement
iii) Transaction Control Statement
iv) Session Control Statement
v) System Control Statement
vi) Embedded SQL Statement
1 Data Definition Language (DDL) or Data Description Language (DDL)
9 i. It is a standard for commands that defines the different structures in a database.
ii. DDL statements are used to create structure of a table, modify the existing structure of the table
and remove the existing table.
iii. Some of the DDL statements are CREATE TABLE, ALTER TABLE and DROP TABLE
2 Data Manipulation Language (DML)
0 i. These statements are used to access and manipulate data in existing tables.
ii. The manipulation includes inserting data into tables, deleting data from the tables, retrieving
data and modifying the existing data.
iii. The common DML statements are SELECT, UPDATE, DELETE and INSERT.
2 Data type
1 Each value manipulated by SQL Database has a data type.
The data type of a value associates a fixed set of properties with the value.
In SQL there are three main data types: Character, Number, and Date types.
2 Character data types stores character (alphanumeric) data, which are words and free-form text.
2 Character data types are;
i) CHAR
ii) VARCHAR

2|Page
Database Concepts and SQL

2 CHAR: CHAR should be used for storing fixed length character strings.
3 String values will be space/blank padded (The adding of meaningless data [usually blanks] to a unit
of data to bring it up to some fixed size) before they are stored on the disk.
If this type is used to store variable length strings, it will waste a lot of disk space (always allocate
fixed memory) .
If we declare data type as CHAR, then it will occupy space for NULL values.
Format: CHAR(n)
Fixed-length character string having maximum length n.
2 VARCHAR: Varchar is a variable character stringFormat: VARCHAR (n)
4 Variable-length character string having maximum length n.
Format: VARCHAR2 (n)
Example:
CHAR(10) has fixed length, right padded with spaces.
VARCHAR(10) has fixed length, right padded with NULL
Name char (10): Suppose if we store Name is as "Ravi", then first four places of the ten characters
are filled with Ravi and the remaining 6 spaces are also allocated to Name. Thus, the size of name is
always ten.
Name varchar (10): Suppose if we store Name is as "Ravi", then first four places of the ten
characters are filled with Ravi and the remaining 6 spaces are filled with NULL.
.

2 Numeric data types are mainly used to store number with or without fraction part.
5 The numeric data types are:
2 1. NUMBER
6 2. DECIMAL
3. NUMERIC
4. INT
5. FLOAT
NUMBER: The Number data type stores fixed and floating-point numbers. The Number data type is
used to store integers (negative, positive, floating) of up to 38 digits of precision.
The following numbers can be stored in a Number data type column:
Positive numbers
Negative numbers
Zero
Format:
NUMBER (p, s)
Where;
– 'p' is the precision or the total number of significant decimal digits, where the most significant digit
is
the left-most nonzero digit and the least significant digit is the right-most known digit.
– 's' is the scale or the number of digits from the decimal point to the least significant digit.
DECIMAL and NUMERIC: Decimal and numeric data types have fixed precision and scale.
Format:
DECIMAL[ (p[ , s] )] and NUMERIC[ (p[ , s] )]
Square brackets ([ ]) are option.

3|Page
Database Concepts and SQL

where;
– 'p' is the precision or the total number of significant decimal digits, where the most significant digit
is
the left-most nonzero digit and the least significant digit is the right-most known digit.
– 's' is the scale or the number of digits from the decimal point to the least significant digit.
INT/INTEGER: The int data type is the integer data type in SQL. This used to store integer number
(without any fraction part).
FLOAT: This data type is used to store number with fraction part(real numbers).
2 Q1 In a table in MYSQL database, an attribute A of datatype varchar(20)has the value “Keshav”.
7 The attribute B of datatype char(20) has value “Meenakshi”. How many characters are occupied by
attribute A and attribute B?
a. 20,6 b. 6,20 c. 9,6 d. 6,9

ans b 6,20

Q2In MYSQL database, if a table, Alpha has degree 5 and cardinality 3, and another table, Beta has
degree 3 and cardinality 5, what will be the degree and cardinality of the Cartesian product of Alpha
and Beta?
a. 5,3 b. 8,15 c. 3,5 d. 15,8

ans b 8,15
2 DATE
8 Date is used to store valid date values
The date format is: YYYY-MM-DD
Cartesian product
SQL joins are used to relate information in different tables.
It combines fields from two or more tables by comparing values of common columns (join
condition).
A join condition is a part of the SQL query that retrieves rows from two or more tables.
If join condition is ommitted or if it is invalid, then join operation will result in a Cartesian
product.
Cartesian product is a binary operation and is denoted by (x) Cartesian product returns a number
of rows equal to number of rows in the first table multiply by number of rows in the second
table. At the same time, number of columns equal to number of columns in the first table added
by number of columns in the second table.

4|Page
Database Concepts and SQL

5|Page

You might also like