1 8.10.2024 Database Basics, DDL-1
1 8.10.2024 Database Basics, DDL-1
• Data, Information
• Data Store – File and Database
• DBMS vs. RDBMS
• Types of Data
• MySQL Overview
• SQL
• Working with DDL
--------------------------------------------------------------------------------------------------------------------------
Data vs Information
• Data is the raw or unprocessed fact.
• Example:
o Student name
o Student age
o Student address
• The process data is called information.
Data Store
• It is a place where we can store data.
• There are 2 types of data store:
o Temporary date store
▪ RAM
o Permanent data store
▪ File, Database
-------------------------------------------------------------------------------------------------------------------------------
Disadvantages of File
• Data Redundancy
• Data Inconsistency
• Difficulty in Accessing Data
• Integrity Problem
• Atomicity Problems
• Data Indexing
• Concurrency
------------------------------------------------------------------------------------------------------------------------------
Database
• It is used to store data.
• Example: MySQL, PostgreSQL, Oracle, SQL Server etc.
DBMS
• DBMS stands for Database Management System.
• It's a software application that helps you create, manage, and access databases.
• Types of DBMS
o Hierarchical
o Network
o Relational Database Management System (RDBMS)
o Object Database Management System
RDBMS
• It's a type of database management system (DBMS) that organizes data in tables, with rows
representing records and columns representing attributes.
Table
• Every relational database stores data in tables.
• We can have many tables in one database.
• Table has columns and rows.
• Each row stores information about one object.
• Column identify the kind of information is stored in them
Types of Data
• Structured data
• Semi-Structured data
• Unstructured data
Structured Data
• Structured data means organized and formatted data.
• Example:
o Customer information:
▪ Name: John
▪ Age: 30
▪ Address: 123 Main St
▪ Phone: 555-1234
• Data store:
o Relational databases like MySQL, Oracle etc.
o NoSQL databases like MongoDB, Cassandra
Semi- Structured Data
• Partially organized with some level of formatting.
• Example
o JSON data
{
"name": "John ",
"age": 30,
"address": "123 Main St"
}
• Data store:
o NoSQL databases like MongoDB, Cassandra
o Object storage like Amazon S3, Azure blob storage.
Unstructured data
• Unorganized data is called unstructured.
• Example;
o Image
o Audio
o Video
o Etc.
• Data store:
o Object storage like Amazon S3, Azure blob storage.
o Cloud storage: Dropbox, Google Drive, Microsoft OneDrive
-------------------------------------------------------------------------------------------------------------------------------
MySQL
• MySQL is an open-source relational database management system (RDBMS).
Communicating with MySQL
Managing Database
• show databases;
• create database <database-name>;
• drop database <database-name>;
• create database if not exists <database-name>;
• drop database if exists <database-name>;
• use <database-name>;
• select database();
SQL (Structure Query Language)
• SQL is a standard language used for interacting with relational databases.
• Different Sub Languages of SQL:
o DDL (Data Definition Language)
o DML (Data Manipulation Language)
o DQL (Data Query Language)
o TCL (Transaction Control Language)
o DCL (Data Control Language)
DDL
• These commands are given to work with database objects such as tables, views etc.
• Example:
o CREATE
o ALTER
o DROP
o TRUNCATE
DML
• These commands are given to store/ update/ delete data.
• Example:
o INSERT
o UPDATE
o DELETE
DQL
• These commands are given to fetch/read data.
• Example:
o SELECT
TCL
• These commands are given to control transaction.
• Example:
o COMMIT
o ROLLBACK
o SAVEPOINT
DCL
• These commands are given to manage permission.
• Example:
o GRANT
o REVOKE
-------------------------------------------------------------------------------------------------------------------------------
Creating Table
Syntax:
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
...
);
Modifying Table
Add New Column
• ALTER TABLE employee ADD address varchar(100);
• It will add column at last. If we want to add column in specified location then use after keyword.
• alter table dish add age varchar(10) after employeeid;
Modify Existing Column
• ALTER TABLE employee MODIFY address varchar(10);
• ALTER TABLE employee MODIFY address int;
Rename Existing Column
• ALTER TABLE employee CHANGE address age int;
Delete Existing Columns
• ALTER TABLE employee DROP age;
Rename Table
• RENAME TABLE old_table_name TO new_table_name;
Delete Table
• DROP TABLE table_name;
Deleting All Rows from Table
• TRUNCATE table_name;