SQL
SQL
SQL
Data Data
Definition Manipulation
Language Language
CREATE SELECT
ALTER INSERT INTO
DROP UPDATE
RENAME
DELETE
ඇයි MySQL?
SHOW tables;
CREATE TABLE table_name (column_name1
data_type(length) NOT NULL, column_name2
data_type(length) NOT NULL, primary key(column_name));
උදා:
CREATE TABLE Persons (PersonID int(8) NOT NULL,
LastName varchar(60), FirstName varchar(60) NOT NULL,
Address varchar(100) NOT NULL, City varchar(30) , PRIMARY
KEY(PersonID));
උදා:
CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
CHECK (Age>=18)
);
CREATE TABLE table_name (column_name1 data_type(length)
NOT NULL, ……., primary key(column_name));
උදා:
• CREATE TABLE Persons (PersonID int(8) NOT NULL, LastName
varchar(60), FirstName varchar(255) NOT NULL, Address
varchar(100) NOT NULL, City varchar(30) , PRIMARY
KEY(PersonID));
Persion
PersonID PersonName
PK
OrderDetails
OrderID OrderDesc PersonID
FK
CREATE TABLE table_name (column_name1 data_type(length) NOT NULL, column_name2
data_type(length) NOT NULL, …….
PRIMARY KEY(column_name1),
FOREIGN KEY(column_name2) REFERENCES second_table_name (column_name2));
උදා:
CREATE TABLE Order (OrderID int(8) NOT NULL, OrderDesc varchar(50), PersonID int(8) NOT
NULL, PRIMARY KEY(OrderID), FOREIGN KEY(PersonID) REFERENCES Person(PersonID);
ALTER TABLE <table_name> ADD PRIMARY KEY <column_name>
උදා:
ALTER TABLE Persons ADD PRIMARY KEY(PersonID));
• ALTER TABLE table_name ADD FOREIGN KEY
column_name REFERENCES
second_table_name (column_name)
• උදා:
ALTER TABLE Orders
ADD FOREIGN KEY (PersonID) REFERENCES Person(PersonID);
• ALTER TABLE table_name DROP PRIMARY KEY;
• ALTER TABLE table_name DROP FOREIGN KEY;
උදා:
ALTER TABLE Persons DROP PRIMARY KEY(PersonID));
UPDATE Customers
SET ContactName = ‘T.P.Bandara', City = ‘Rajagiriya'
WHERE CustomerID = 1;
PersonID = 1122 ලන උඳැකියානයේ (record) FirstName , Amal යස යලනස්
කිරීම
PersonID = 1122 ලන උඳැකියානයේ (record) FirstName , Amal යස යලනස් වූ ඳසු
Output
• DELETE FROM table_name WHERE
some_column=some_value;
උදා:
SELECT CustomerName, City, Country FROM Customers WHERE Country= ‘Sri Lanka’;
> විාතර
< කුඩාතර
<> අසමාන .
සම ර version ල != කුණද භාවිත යේ
IN To specify multiple possible values for a column උඳැකියක් ස ා බහු අගයන් ඳලතින විට භවිත කරයි
AND
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;