DBMS
DBMS
DBMS
System
BATCH 5
What is Database ?
The database is a collection of inter-related data which is used to retrieve, insert and delete the data efficiently.
It is also used to organize the data in the form of a table, schema, views, and reports, etc.
For example: The college Database organizes the data about the
admin, staff, students and faculty etc.
Using the database, you can easily retrieve, insert, and delete the
information.
Database Management System
Database management system is a software which is used to manage the database. For
example: MySQL, Oracle , etc are a very popular commercial database which is used in different
applications.
DBMS provides an interface to perform various operations like database creation, storing data in it,
updating data, creating a table in the database and a lot more.
It provides protection and security to the database. In the case of multiple users, it also maintains data
consistency.
What is MySQL?
This model is designed for the end-users called clients to access the resources from a central
computer known as a server using network services.
SQL Commands
MySQL Create Database
We can create a new database in MySQL by using the CREATE DATABASE statement with the below syntax:
SHOW DATABASES;
We can use the below command to access the database that enables us to create a table and
other database objects.
USE database_name;
• We can drop/delete/remove a MySQL database quickly with the MySQL DROP DATABASE
command.
• It will delete the database along with all the tables, indexes, and constraints permanently.
• A table is used to organize data in the form of rows and columns and used for both storing and
displaying records in the structure format.
• It is similar to worksheets in the spreadsheet application. A table creation command requires three
things:
database_name It is the name of a new table. It should be unique in the MySQL database that we have selected.
The IF NOT EXIST clause avoids an error when we create a table into the selected database
that already exists.
column_definition It specifies the name of the column along with data types for each column. The columns in table
definition are separated by the comma operator. The syntax of column definition is as follows:
column_name1 data_type(size) [NULL | NOT NULL]
table_constraints It specifies the table constraints such as PRIMARY KEY, UNIQUE KEY, FOREIGN KEY,
CHECK, etc.
We need to use the following command to see the newly created table:
SHOW TABLES;
We can use the following command to see the information or structure of the newly created table:
DESCRIBE table_name;
MySQL ALTER Table
MySQL ALTER statement is used when you want to change the name of your table or any table
field.
It is also used to add or delete an existing column in a table.
The ALTER statement is always used with "ADD", "DROP" and "MODIFY" commands according
to the situation.
6) RENAME table
Syntax:
ALTER TABLE table_name
RENAME TO new_table_name;
MySQL TRUNCATE Table
MySQL INSERT statement is used to store or add data in MySQL table within the database.
We can perform insertion of records in two ways using a single query in MySQL:
1. Insert record in a single row
2. Insert record in multiple rows
Syntax:
The below is generic syntax of SQL INSERT INTO command to insert a single record
in MySQL table:
INSERT INTO table_name ( field1, field2,...fieldN )
VALUES
( value1, value2,...valueN );
If we want to insert multiple records within a single command, use the following statement:
MySQL UPDATE query is a DML statement used to modify the data of the MySQL
table within the database.
The UPDATE statement is used with the SET and WHERE clauses. The SET
clause is used to change the values of the specified column. We can update
single or multiple columns at a time.
Syntax:Following is a generic syntax of UPDATE command to modify data into
the MySQL table:
UPDATE table_name
SET column_name1 = new-value1,
column_name2=new-value2, ...
[WHERE Clause]
MySQL DELETE Statement
MySQL DELETE statement is used to remove records from the MySQL table that
is no longer required in the database.
DELETE FROM table_name WHERE condition;