Professional Documents
Culture Documents
My Own SQL Command Note For Batch3
My Own SQL Command Note For Batch3
Datatype in sql
varchar(length) - varchar(255) -
char(lenght) – fixed length – place with space
int
double(total number of digit, total number of decimal point)
Boolean – true or false
Date – yyyy/mm/dd
Naming convention
- identifier must start with a letter (eg: Student)
-identifier cannot contain space. (instead use underscore)
-no longer than 128 character
-can contain letter, number, underscore
SQL statement
-Reserved word – UPPER CASE
-User defined word – lower case
-statement terminator (;)
Reserved word
-SELECT, UPDATE, DELETE, INSERT
-SELECT – to query data in the database
-UPDATE – to update data in a table
-DELETE – to delete data from the table
-INSERT – to insert data into a table
User defined word
-made by user
-tablename, columnname
Naming convention
Table name – first letter Uppercase letter
Column name – first letter lowercase – the other word first letter UPPER CASE
PropertyForRent
1. INSERT INTO Branch (branchNo, street, city, postCode) VALUES ('b005', '22 Deer Rd',
'London', 'SW1 4EH');
2. INSERT INTO Branch (branchNo, city, street, postCode) VALUES ('b007', 'Aberdeen','16 Argyll
St', ‘AB2 3SU’);
Rename COLUMN
1. ALTER TABLE tablename
RENAME COLUMN oldcolumnname TO newcolumnname;
Drop table
DROP TABLE tablename;
Add Foreign Key into Existing Table (with Constraint Name + Referential Constraint)
ALTER TABLE tablename
ADD CONSTRAINT constraintname
FOREIGN KEY(columnname) REFERENCES parenttablename(keycolumnname) ON DELETE
SET NULL;
Referential Action
-ON DELETE SET NULL
-ON DELETE CASCADE
-ON DELETE NO ACTION (language default setting)
-ON DELETE SET DEFAULT
2. select city
From branch
Group by city;
6. select branchNo
From staff
Group by branchNo;
9. select position
From staff;
PurchaseTableB
customerCode customerName repCode
2051 Thiri Soe A12
4293 Thurein B30
5018 Myo Myo A11
Check Constraint
No_of_Room no more than 15
Salary 10000 – 50000
branchNo B001 – B999
gender M or F
drop column
alter table tablename
drop column columnname;
In
Between
Operator (logical and comparison)
Distinct eg and defn
Null (eg)
Aggregate function (select, having) eg
Temporary column name, tablename
Check (in, between)
Check constraint in Q1
Grant – in Q1
Revoke
Create Domain
Create View
Update
Delete
Join (inner, left, right)
Union
Intersect
Except