SQLnew
SQLnew
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 :
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.
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
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;
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