0% found this document useful (0 votes)
9 views

MySQL Shortly

this is short version of ms sql
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

MySQL Shortly

this is short version of ms sql
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

MySQL Shortly

1. Datatypes:
Signed: Can store both positive and negative values.
Unsigned: Can only store non-negative values (zero or positive values).

CREATE TABLE example_unsigned_tinyint (


id tinyint unsigned,
quantity tinyint unsigned);
INTEGER Data Types:

TINYINT: Range: -128 to 127 (signed) or 0 to 255 (unsigned).


SMALLINT: Range: -32,768 to 32,767 (signed) or 0 to 65,535 (unsigned).
MEDIUMINT: Range: -8,388,608 to 8,388,607 (signed) or 0 to 16,777,215
(unsigned).
INT or INTEGER: Range: -2,147,483,648 to 2,147,483,647 (signed) or 0 to
4,294,967,295 (unsigned).
BIGINT: Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
(signed) or 0 to 18,446,744,073,709,551,615 (unsigned).
Text Data Types:
CHAR(n): Fixed-length character string, where n is the maximum length.
VARCHAR(n): Variable-length character string with a maximum length of n.
TEXT: Variable-length text string with no fixed length.
Date and Time Data Types:
DATE: Date values in the format 'YYYY-MM-DD'.
TIME: Time values in the format 'HH:MM:SS'.
DATETIME: Date and time values in the format 'YYYY-MM-DD HH:MM:SS'.
TIMESTAMP: Similar to DATETIME but automatically updates to the current
timestamp.
YEAR: Year values in 2-digit or 4-digit format.
Boolean Data Type:
BOOLEAN or BOOL: Represents boolean values (0 for false, 1 for true).
ENUM and SET Data Types:
ENUM is used when you want to store one value from a predefined list, and
you can choose only one option from the list for each row.
SET is used when you want to store multiple values from a predefined list,
and you can choose multiple options from the list for each row.
Create a table to store user communication preferences
CREATE TABLE user_communication_preferences (
user_id INT PRIMARY KEY,
communication_methods SET('Email', 'SMS', 'Phone', 'Social
Media', 'Mail')
);
INSERT INTO user_communication_preferences (user_id,
communication_methods)
VALUES
(1, 'Email,SMS'),
(2, 'Phone,Social Media'),
(3, 'Email,Phone,Social Media'),
(5, 'Email,SMS,Phone,Social Media');
2. Autocommit = off თუ ამას გამოვრთავთ დაუყოვნებლივ აღარ
შეინახება. ყოველ შესვლზე თავიდან უნდა დავაყენოთ.
3. Commit; როცა ამას ავკრებთ შეინახება.
4. Rollback; უკან დააბრუნებს ან commit- ამდე როცა გამოვრთეთ
Autocommit.
5. მიმდინარე დროის ფუნქციები
 Current_date()-თარიღი
 current_time()-დრო(საათი)
 now()-'YYYY-MM-DD HH:MM:SS'
6. unique - ეს არის შეზღუდვა და იმ სვეტში რომელსაც ესდაედება აღარ
შეიძლებოდეს იქნება დუბლიკატების ჩაწერა.
7. Not null - ეს არის შეზღუდვა და იმ სვეტში რომელსაც ესდაედება აღარ
შეიძლებოდეს იქნება null მნიშვნელობის ჩაწერა.
8. Check - შეზღუდავ რომელსაც ვადებთ სვეტს და მასში მითითებული შეზღუდვამ
უნდა იმუშაოს ამავე სვეტში მინიჭებულ მნიშვნელობებზე.
9. Default - არის სვეტის მნიშვნელობა იმ შემთხვევაში თუ არ მიენიჭება
მნიშვნელობა.
10. Primary key - ძირითადი გასაღების სვეტები არ შეიძლება შეიცავდეს NULL
მნიშვნელობებს. თითოეულ მწკრივს უნდა ჰქონდეს უნიკალური , არა null
მნიშვნელობა პირველადი გასაღების სვეტებში.
11. Auto increment - ედება სვეტს და ეს სვეტი გაიზრდება ერთით. შეგვიძლია
მივუთითოთ რომელი მნიშვნელობიდან დაიწყოს ზრდა.
12. Foreign key - ეს არის სვეტების კავშირი ორი სხვადასხვა ცხრილიდან.
13. One to many relationship:
 Tables: authors and books.
 Relationship: one author can write many books.
 Example schema: ერთი ავტორი დაკავშირებულია ბევრ წიგნთან.
14. Many to many relationship:
 Tables: students and courses.
 Relationship: many students can enroll in many courses and each course can have
many students.

15. Self referring:


 Tables: employees.
 Relationship: an employee can have a manager who is also an employee.
 Example chema:

16. On delete – cascade/set null – when we delete parent table in case of cascade whole row
will be deleted and in case of set null row rill be set as null.
17. Inner join - დააბრუნებს მხოლოდ შესაბამისობაში მყოფ სტრიქონებს.
18. Right join - მარჯვენა შეერთება ნიშნავს რომ მარჯვენა ცხრილი გადაიწერება
ბოლომდე და შესაბამისობაში მოვა მარცხენა.
19. Left join - მარცხენა შეერთება ნიშნავს რომ მარცხენა ცხრილი გადაიწერება
ბოლომდე და შესაბამისობაში მოვა მარჯვენა.
20. Functions:

 Mathematical Functions:
 ABS(): Returns the absolute value.
 ROUND(): Rounds a number to a specified number of
decimal places.
 CEIL(): Rounds a number up to the nearest
integer.
 FLOOR(): Rounds a number down to the nearest
integer.
 POWER(): Raises a number to a specified power.
 SQRT(): Returns the square root of a number.
 String Functions:
 CONCAT(): Concatenates two or more strings.
 LENGTH(): Returns the length of a string.
 SUBSTRING(): Extracts a substring from a string.
 UPPER(): Converts a string to uppercase.
 LOWER(): Converts a string to lowercase.
 TRIM(): Removes leading and trailing spaces.
 Date and Time Functions:
 NOW(): Returns the current date and time.
 DATE(): Extracts the date part from a datetime
value.
 TIME(): Extracts the time part from a datetime
value.
 DATEDIFF(): Calculates the difference between two
dates.
 DATE_FORMAT(): Formats a date in a specified
format.
 Aggregate Functions:
 SUM(): Calculates the sum of a set of values.
 AVG(): Calculates the average of a set of values.
 COUNT(): Counts the number of rows in a result set.
 MIN(): Returns the minimum value in a set of
values.
 MAX(): Returns the maximum value in a set of
values.
 Control Flow Functions:
 IF(): Returns one value if a condition is true, and
another if it's false.
21. Logical operators:
 And:
 Or:
 Not:
 In:
SELECT * FROM table_name WHERE column_name IN (value1, value2,
value3);

 Between:
 Like:
 In null/is not null:
22. Wild cards:
 s%:
 sp%:
 %b:
 Ca_hie_:
 _a%:
23. Order by:
 Order by column desc/asc: ზრდადობით და კლებადობით
დალაგება.
 Order by column1 desc/asc, column2 desc/asc: როცა
ერთიდაიგივე მნიშვნელობა ექნება დაალაგებს მეორე
კრიტერიუმის მიხედვით.
 Asc - სტრინგის ზომა.
24. Limit:
 რამდენ სტრიქონზე იმუშაოს, მაგალითად როცა გვინდა ცხრილის
ამოღება მაშინ იმდენ სტრიქონს ამოიღებს ცხრილიდან
რამდენსაც მივუთითებთ.
 როცა ორი მნიშვნელობა აქვს დაიწყებს პირველი მნიშვნელობის
შესაბამის სტრიქონიდან და ამოიღებს იმდენ მნიშვნელობას
რამდენიც წერია მეორე მნიშვნელობად.
25. Union:
 როცა გვინდა select-ით უბრალოდ ორი ცხრილი ვაჩვენოთ.
 თუ განსხვავებული რაოდენობის სვეტები აქვთ უნდა მოვნიშნოთ
მხოლოდ.
 union – not duplicates.
 union all – with duplicates.
26. Self join:
 როცა გვინდა იერარქიულად დავალაგოთ ერთი ცხრილის მიხედვით .
27. View:
 იქმნება ნებისმიერი მონაკვეთი(ის სვეტები რომელსაც მივუთითებთ )
ცხრილის და არ გვიწევს ახლის შექმნა.
28. Indexes: მონაცემის ძებნის პროცესი მიმდინარეობს ჯერ იწყებს პირველი
სტრიქონიდან და ჩადის ბოლოში. ინდექსით კი მხოლოდ ერთ სვეტს ამოწმებს.
ეს კარგია როცა დიდი მონაცემი გვაქვს.
29. Subquery: როცა ვიყენებთ ისეთ ფუნქციას როგორიცაა მაგალითად avg(column)
და შ იმისათვით რომ ეს გამოვიყენოთ სხვა ახალ ფუნქციაში უნდა მოვნიშოთ
რადგან ეს მნიშვნელობა არის ცხრილის პირველ უჯრაში. SELECT AVG(salary)
FROM employees ეს არის მნიშვნელობა რომელიც შეგვიძლია გამოვიყენოთ
ყველგან.
30. Grouped by:
 ვთქვათ გვაქვს ეს ცხრილი და გვაქინტერესებს რა იყო ჩვენი
შემოსავალი თითოეულ თვეს. მოცემული გვაქვს იანვრის, თებერვლის
და მარტის მონაცემები.
 მონიშვნის დროს თუ გვინდა გამოვიყენოთ where მაშინ უნდა
გამოვიყენოთ მის ნაცვლად having.
31. Rollup: როცა მონიშვნის დროს ვითვლით ჯამს თითოეული ჯგუფისთვის და ასევე
გვინდა ბოლოში საბოლოო ჯამიც ვნახოთ.
32. Stored procedures: ქმნის ფუნქცის რომელსაც შემდეგში რამდენჯერაც გვინდა
იმდენჯერ გამოვიძახებთ.
33. Trigger: ტრიგერი MySQL-ში არის SQL განცხადებების ერთობლიობა, რომელიც
ავტომატურად სრულდება კონკრეტული მოვლენების საპასუხოდ , როგორიცაა
მონაცემთა ცვლილებები (INSERT, UPDATE, DELETE) მაგიდაზე. ტრიგერები
გამოიყენება მონაცემთა მთლიანობის აღსასრულებლად, ამოცანების
ავტომატიზაციისა და მონაცემთა ბაზაში თანმიმდევრულობის
შესანარჩუნებლად.

You might also like