0% found this document useful (0 votes)
13 views

SQLnew

Uploaded by

TECHNICAL GAMER
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

SQLnew

Uploaded by

TECHNICAL GAMER
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

DBMS

DATA BASE
MANAGEMENT
SYSTEM
FILE SYSTEM
•File system A file can be understood as a
container to store data in a computer.
•File can be store on a storage device on a
computer system.
•Content of a file can be text, computer
program code, comma separated values(CSV),
pictures, audio, videos are also files.
•File store on a computer can be accessable
directly and searched for desired data.
Drawback of file system
•Data redendency
•Data inconsistency
•Data isolation
•Data integrity
•Security problem
•Difficulty in access
Database :

A database is an organised collection of data, which in turn


is a collection of raw facts, figure, number and quantities. It
is a collection of files, tables that act as a single centralised
repository for the storage of data.
Database is intregated as well as shared. For eg: all file
belonging to one organisation will be treated as the
database of that org.
The data is the smallest component in file org. a database is
the largest component in file org.
Database terminologies:

Database

Table/ file

Record

Dataitem/ field

Data / character
DBMS:
•Database is a collection of interrelated data
and DBMS is a set of program used to
access that data. DBMS is a computerised
record keeping system. DBMS is facilitates
the process of defining, constructing and
manipulating database for various
application.
DBMS RDBMS
1.DBMS application store data as 1.RDBMS application store data in
a file. a tabular form.
2.In DBMS data is generally 2.In RDBMS table has an
stored in either a hierarchical identifier called primary key and
form or a navigational form. data value are store in the form
3.DBMS use file system to store of tables..
data , so there will be no 3.RDBMS data value are store in
relation between the tables . form of table, so relationship
4.DBMS is meant to be for small between these data values will
organisation and deal with be store in the form of tables.
small data, it support single 4.RDBMS designed to handle
user. large amount of data. It support
5.Example of DBMS are file multiple users.
system, xml. 5.Example of RDBMS are mysql,
oracle.
Relational data Model:
• Data is organised in two-dimensional table called relations. It developed by
Ted Codd.
• A relational model consist of a collection of tables, each of which is
assigned a unique name,i.e represents a database as a collection of
relations or tables.
Advantages Disadvantages
1. Changes in table donot 1. RDBMS incur h/w and
effect the data access s/w overheads.
2. It represent in table 2. The size of database
form. become very large.
3. Easy and simple to
understand.
4. Mathematical
operation can be
successfully carried by
using RDBMS.
Basic terminology:
Entity: it is that exists and about which we can store some
information. Eg: student, employee, etc. entity become the name
of the table.
Attribute: An attribute is a set of values of a particular type. A table
consist of several records(rows), each record can be broken into
several smaller entity known as attribute or column. A set of
attribute define the characterstics of an entity. Eg: student entity
consist of 4 field- rollno, name, address, gender.
Tuple: Each row is known as tuple(record). Eg: student table has 10
records.
Cardinality of relations: it is the number of records or tuple in
relation.
Degree of relation: : number of column is known as degree
of relation.

Domain: it represent the kind of data in the attribute.


Domain is a unique set of values permitted for an attribute
in a table. Eg: in student table domain for gender is two
“M”,”F”.
Body of relation: it consist of an unordered set 0 or more
tuple.
Properties of relation:

•All row in a relation must be distinct.


•Ordering of row and columns are
immaterial
•For a row, a column can not have
more than one value.
•All the values in a column have the
same datatype.
Database keys:
A key in a database is an attribute or set of attributes that
help to uniquely identify a tuple (row) in a relation . Key are
also used to established relationship between the different
tables and columns of a relational database. Individual
value in a key are called key value.
Primary keys:
• It is a set of one or more attribute which uniquely
identify a row in a table.
• It always unique in nature.
• It arrange in table form.
• Cannot left null
• Table has only one primary key.
Candidate keys:
• All the attributes in a relation that are candidate or
are capable of becoming a primary key are termed
as the candidate key.
• Candidate key- primary key=alternate key

Alternate keys:
• A candidate key which is not a primary key is called
alternate key.
Foreign key:
• It is a non key attribute whose value is derived from
the primary key of another table. i.e primary key in
some other table has relationship with original table
• Foreign key is used to represent the relationship between
two relations,. A foreign key is an attribute whose value is
derived from primary key of another relation.
• This means that any attribute of a relation, which is used
to refer content from other relation, become foreign key if
it refers to the primary key of referenced relation. The
referencing relation is called foreign relation.
• In some cases, foreign key is null if it is not the part of
primary keyof the foreign table. The relation in which the
reference primary key is defined is called primary relation.
SQL
SQL is a sequential language for
storing, manipulation and retrieving
data in data base.
SQL history

•The SQL programming language


was first developed in 1970’s by
IBM. The programming language
known as then SEQUEL.
Characterstics of MYSQL:
• SQL is easy to learn.
• SQL is used to access data from relational database management systems.
• SQL can execute queries against the database.
• SQL is used to describe the data.
• SQL is used to define the data in the database and manipulate it when
needed.
• SQL is used to create and drop the database and table.
• SQL is used to create a view, stored procedure, function in a database.
• SQL allows users to set permissions on tables, procedures, and views.
Advantages of MYSQL:
• There are the following advantages of SQL:
High speed
• Using the SQL queries, the user can quickly and efficiently retrieve a large
amount of records from a database.
No coding needed
• In the standard SQL, it is very easy to manage the database system. It
doesn't require a substantial amount of code to manage the database
system.
Well defined standards
• Long established are used by the SQL databases that are being used by ISO
and ANSI.
Portability
• SQL can be used in laptop, PCs, server and even some
mobile phones.
Interactive language
• SQL is a domain language used to communicate with the
database. It is also used to receive answers to the
complex questions in seconds.
Multiple data view
• Using the SQL language, the users can make different
views of the database structure.
Classification of SQL statements:

Data Definition Language (DDL) Commands

DDL, which stands for Data Definition Language, is a subset of SQL


(Structured Query Language) commands used to define and modify the
database structure. These commands are used to create, alter, and delete
database objects like tables, indexes, and schemas. The primary DDL
commands in SQL include:

CREATE: This command is used to create a new database object. For example, creating a new table, a view, or
a database.
•Syntax for creating a table: CREATE TABLE table_name (column1 datatype, column2 datatype, ...);

ALTER: This command is used to modify an existing database object, such as adding, deleting, or modifying columns in an
existing table.
•Syntax for adding a column in a table: ALTER TABLE table_name ADD column_name datatype;
•Syntax for modifying a column in a table: ALTER TABLE table_name MODIFY COLUMN column_name datatype;
DROP: This command is used to delete an existing database object like a table, a view, or
other objects.
•Syntax for dropping a table: DROP TABLE table_name;

RENAME: Used to rename an existing database object.


•Syntax: RENAME TABLE old_table_name TO new_table_name;
Datatype
•Int
•Float
•Char
•Varchar
•Date
•Time
Char
• Char(n) specifies character type data of length n where n could be any
value from 0 to 255.
• Char is of fixed length , means , declaring char(10) implies to reserve space
for 10 characters.
• If data does not have 10 characters , MYSQL fills the remaining 6 character
with spaces padded on the right.

VarChar
VarChar(n) specifies character type data of length n where
n could be any value from 0 to 65535.
Difference between char and varchar

Char Varchar
1. It is a fixed size. 1. It’s a variable length datatype.
2. In this, chances of memory 2. Memory doesnot get wastage.
wastage is high.
3.Example : name char(20) 3. Example : name varchar(20)
That means 20 characters fixed. If That means 20 chars not fixed
you need only 4 chars then remaining part can adjust by SQL.
remaining char get wasted because
here you cannot use those 4 chars.
4. When we sure then use this. 4. When we not sure then we use
this.

5. Fast 5. slow
Int
•Int specifies an integer value.
•Each int value occupies 4 bytes of storage.
•For value larger then that we have to use
BIGINT , which occupies 8 bytes.
Date : YYYY-MM-DD
TIME: HH:MM:SS
CONSTRAINTS
Create table student
(
Rollno int primary key,
):
UNIQUE KEY

•The purpose of unique key is to


ensure that the information in the
column for each row must be
unique.
•Unique key must have NULL value.
NOT NULL
•The column having NOT NULL
constraints can not contain NULL
value.
DEFAULT CONSTRAINTS
•Default constraints used to assign the default
valueto a column, when user does not provide
any value.
•If user provide any value then it will be
overwrite.

Create table student


(
Rollno int primary key, regno int unique, name
varchar(20) not null, gender char(1) default ‘f’
):
Data Manipulation Language (DML)
• Data Manipulation Language (DML) is a subset of SQL commands
used for adding (inserting), deleting, and modifying (updating)
data in a database. DML commands are crucial for managing the
data within the tables of a database. The primary DML
commands in SQL include:

INSERT: This command is used to add new rows (records) to a table.


•Syntax: INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1,
value2, value3, ...);

UPDATE: This command is used to modify the existing records in a


table.
•Syntax: UPDATE table_name SET column1 = value1, column2 = value2, ...
WHERE condition;
•The WHERE clause specifies which records should be updated.
Without it, all records in the table will be updated
DELETE: This command is used to remove one or more rows from a table.
•Syntax: DELETE FROM table_name WHERE condition;
•Like with UPDATE, the WHERE clause specifies which rows should be deleted. Omitting
the WHERE clause will result in all rows being deleted.

SELECT: Although often categorized separately, the SELECT command is


sometimes considered part of DML as it is used to retrieve data from the
database.
•Syntax: SELECT column1, column2, ... FROM table_name WHERE condition;
•The SELECT statement is used to query and extract data from a table, which
can then be used for various purposes.
Data Control Language (DCL)

• Data Control Language (DCL) is a subset of SQL commands


used to control access to data in a database. DCL is crucial
for ensuring security and proper data management,
especially in multi-user database environments.
Transaction Control Language (TCL)

•Transaction Control Language (TCL) is a subset


of SQL commands used to manage transactions
in a database. Transactions are important for
maintaining the integrity and consistency of
data.

You might also like