Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

MySQL Database Management, Study notes of Programming Paradigms

An overview of the fundamental sql statements used for database management, including creating and dropping databases and tables, as well as modifying table structures. It covers the syntax and usage of the create database, drop database, create table, drop table, alter table, and select statements. How to add, delete, and modify columns in an existing table, and how to use the where clause to filter records in a select statement. This information is essential for anyone working with relational databases and sql, particularly students or professionals in computer science, information technology, or data-related fields.

Typology: Study notes

2022/2023

Available from 08/09/2024

ashxn
ashxn 🇵🇭

8 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MySQL DATABASE
TheCREATE DATABASEstatement is used to
create a new SQL database.
Syntax:
CREATEDATABASEdatabasename;
CREATEDATABASEtestDB;
TheDROP DATABASEstatement is used to drop
an existing SQL database.
Syntax:
DROPDATABASEdatabasename;
DROPDATABASEtestDB;
The CREATE TABLE statement is used to create a
new table in a database.
Syntax:
CREATETABLEtable_name(
 column1 datatype,
 column2 datatype,
 column3 datatype,
 ....
);
CREATETABLEPersons (
 PersonID int,
 LastName varchar(255),
 FirstName varchar(255),
 Address varchar(255),
 City varchar(255)
);
TheDROP TABLEstatement is used to drop an
existing table in a database.
Syntax:
DROPTABLEtable_name;
DROPTABLEShippers;
TheALTER TABLEstatement is used to add, delete, or
modify columns in an existing table. TheALTER
TABLEstatement is also used to add and drop various
constraints on an existing table.
ALTER TABLE - ADD Column
To add a column in a table, use the following syntax:
ALTERTABLEtable_name
ADDcolumn_name datatype;
ALTERTABLECustomers
ADDEmail varchar (255);
ALTER TABLE - DROP COLUMN
To delete a column in a table, use the following syntax
(notice that some database systems don't allow deleting a
column):
ALTERTABLEtable_name
DROPCOLUMNcolumn_name;
ALTERTABLECustomers
DROPCOLUMNEmail;
ALTER TABLE - MODIFY COLUMN
To change the data type of a column in a table, use the
following syntax:
ALTERTABLEtable_name
MODIFYCOLUMNcolumn_name datatype;
ALTERTABLEPersons
ADDDateOfBirth date;
DROP COLUMN
Example
Next, we want to delete the column named
"DateOfBirth" in the "Persons" table.
We use the following SQL statement:
Example
ALTERTABLEPersons
DROPCOLUMNDateOfBirth;
pf2

Partial preview of the text

Download MySQL Database Management and more Study notes Programming Paradigms in PDF only on Docsity!

MySQL DATABASE  The CREATE DATABASE statement is used to create a new SQL database. Syntax: CREATE DATABASE databasename ; CREATE DATABASE testDB;  The DROP DATABASE statement is used to drop an existing SQL database. Syntax: DROP DATABASE databasename ; DROP DATABASE testDB;  The CREATE TABLE statement is used to create a new table in a database. Syntax: CREATE TABLE table_name ( column1 datatype , column2 datatype , column3 datatype , .... ); CREATE TABLE Persons ( PersonID int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255) );  The DROP TABLE statement is used to drop an existing table in a database. Syntax: DROP TABLE table_name ; DROP TABLE Shippers; The ALTER TABLE statement is used to add, delete, or modify columns in an existing table. The ALTER TABLE statement is also used to add and drop various constraints on an existing table.  ALTER TABLE - ADD Column To add a column in a table, use the following syntax: ALTER TABLE table_name ADD column_name datatype ; ALTER TABLE Customers ADD Email varchar (255);ALTER TABLE - DROP COLUMN To delete a column in a table, use the following syntax (notice that some database systems don't allow deleting a column): ALTER TABLE table_name DROP COLUMN column_name ; ALTER TABLE Customers DROP COLUMN Email;ALTER TABLE - MODIFY COLUMN To change the data type of a column in a table, use the following syntax: ALTER TABLE table_name MODIFY COLUMN column_name datatype ; ALTER TABLE Persons ADD DateOfBirth date;DROP COLUMN Example Next, we want to delete the column named "DateOfBirth" in the "Persons" table. We use the following SQL statement: Example ALTER TABLE Persons DROP COLUMN DateOfBirth;

The MySQL SELECT Statement The SELECT statement is used to select data from a database. The data returned is stored in a result table, called the result-set. SELECT Syntax: SELECT column1 , column2, ... FROM table_name ; SELECT * FROM table_name ; To only display needed column: SELECT UserID FROM tbl_admin; SELECT * FROM tbl_admin; The MySQL WHERE Clause The WHERE clause is used to filter records. It is used to extract only those records that fulfill a specified condition. WHERE Syntax: SELECT column1 , column2, ... FROM table_name WHERE condition ; SELECT * FROM Customers WHERE Country = 'Mexico';