DBMS SQLBasics
DBMS SQLBasics
DBMS SQLBasics
We create data every day and we don’t even realize it. When we wake up in the morning to
check our notifications on our phones, transactions that we do in payment apps or browse
social media it is all stored somewhere. It’s stored on a database.
Database Management System (DBMS)
DBMS is the software that would be installed on your personal computer or on a server,
then you would use it to manage one or more databases
Oracle, MySQL, SQL Server, PostgreSQL are couple of Relational Database Management
Systems (RDBMS)
Companies will install any of these Database Management Systems on their dedicated
machines and users can access that data through network
Client => users machine Database server will have multiple databases
On premises
1 TB + 2TB
Snowflake Architecture
SNOWFLAKE LAYERS
Snowflake’s unique architecture consists of three key layers, all of them with High Availability. The
price is also charged separately for each layer.
Database
A database is an organized collection of data. It is a collection, or a set of tables.
If we take example of banks, bigger banks will maintain multiple databases one for each
department
All accounts related data will be stored in one database, loan related data will be stored in
another database, credit card data will be in another database
How data will be stored in a database+
In RDBMS, the data is stored in database objects called tables. A table is a collection of related
entries and consists of columns and rows.
Everyone would have used Excel, if we correlate database with it. Excel is a collection of sheets.
It contains data in rows and columns.
SQL Commands
o SQL commands are instructions. It is used to communicate with the database. It is also
used to perform specific tasks, functions, and queries of data.
o SQL can perform various tasks like create a table, add data to tables, drop the table,
modify the table, set permission for users.
There are five types of SQL commands: DDL, DML, DCL, TCL, and DQL.
1. Data Definition Language (DDL)
o DDL changes the structure of the table like creating a table, deleting a table, altering a
table, etc.
o All the command of DDL are auto-committed that means it permanently save all the
changes in the database.
o CREATE
o ALTER
o DROP
o TRUNCATE
Syntax:
Example:
Syntax
Example
c. ALTER: It is used to alter the structure of the database. This change could be either to
modify the characteristics of an existing attribute or probably to add a new attribute.
Syntax:
EXAMPLE
d. TRUNCATE: It is used to delete all the rows from the table and free the space containing the
table.
Syntax:
Example:
o INSERT
o UPDATE
o DELETE
a. INSERT: The INSERT statement is a SQL query. It is used to insert data into the row of a
table.
Syntax:
INSERT INTO TABLE_NAME (col1, col2, col3,.... col N) VALUES (value1, value2, value3, .... valu
eN);
Or
For example:
b. UPDATE: This command is used to update or modify the value of a column in the table.
Syntax:
For example:
Syntax:
For example
DELETE FROM SKILLSCALER WHERE SKILLSCALER_NAME="Kiran";
DCL commands are used to grant and take back authority from any database user.
o Grant
o Revoke
Example
Example
TCL commands can only use with DML commands like INSERT, DELETE and UPDATE only.
These operations are automatically committed in the database that's why they cannot be used
while creating tables or dropping them.
o COMMIT
o ROLLBACK
a. Commit: Commit command is used to save all the transactions to the database.
Syntax:
COMMIT;
Example:
b. Rollback: Rollback command is used to undo transactions that have not already been saved
to the database.
Syntax:
ROLLBACK;
Example:
ROLLBACK;
5. Data Query Language
o SELECT
a. SELECT: This is the same as the projection operation of relational algebra. It is used to select
the attribute based on the condition described by WHERE clause.
Syntax:
For example:
Getting started
1. Create Database
CREATE DATABASE database_name
CREATE DATABASE hero_database
2. Create Table