Session 01
Session 01
Management System
IT3223
1.
Introduction
⬡ CREATE DATABASE databasename;
⬡ Create database ADBMS;
⬡ DROP DATABASE databasename;
⬡ Drop database ADBMS;
⬡ Use databasename
⬡ Use mysql;
3
CREATE TABLE table_name (
column1 datatype,
“ column2 datatype,
column3 datatype,
....
);
5
Primary key
⬡ CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
PRIMARY KEY (ID)
);
⬡ ALTER TABLE Persons ADD PRIMARY KEY (ID);
⬡ ALTER TABLE Persons DROP PRIMARY KEY;
6
Foreign key
⬡ CREATE TABLE Orders (
OrderID int NOT NULL,
OrderNumber int NOT NULL,
PersonID int,
PRIMARY KEY (OrderID),
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)
);
⬡ ALTER TABLE Orders
ADD FOREIGN KEY (PersonID) REFERENCES Persons(PersonID);
7
⬡ SELECT column1, column2, ...
FROM table_name;
⬡ SELECT column1, column2, ...
FROM table_name
WHERE condition;
8
⬡ AND Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;
⬡ OR Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;
⬡ NOT Syntax
SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;
9
It is possible to write the INSERT
INTO statement in two ways:
1. Specify both the column names and the values to be inserted:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
2. If you are adding values for all the columns of the table, you do not
need to specify the column names in the SQL query. However, make sure
the order of the values is in the same order as the columns in the table.
Here, the INSERT INTO syntax would be as follows:
10
⬡ UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
⬡ DELETE FROM table_name WHERE condition;
11
2.Users
Create user & Drop user
⬡ create user '[username]'@'[host]' identified by
[password];
Ex:create user 'Admin1'@'localhost’ identified by '123';
To check
⬡ use mysql;
⬡ select user,host from user;
⬡ select user,host,password from user;
⬡ drop user [username]'@'[host] ;
13
Manage user
update user set user='student01' where user='student';
update user set host='localhost' where user='student01' and
host ='vau.jfn.ac.lk’;
set password for 'student01'@'localhost'=password('abcd');
14
Thank you!
15