Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Transcript

What is database ? A database is an organized collection of data, generally stored and accessed electronically from a computer system. Database Management System – DBMS Application එකක් develop කිරීමේදී database එකත් එක්ක වැඩකරන්න සිද්දමවනවා. ඒ අවස්තාමේදී database එකත් එ...

What is database ? A database is an organized collection of data, generally stored and accessed electronically from a computer system. Database Management System – DBMS Application එකක් develop කිරීමේදී database එකත් එක්ක වැඩකරන්න සිද්දමවනවා. ඒ අවස්තාමේදී database එකත් එක්ක ප්‍රදාන වශමෙන් insert, delete, update, search ෙන වැඩ 4 හා අමනකුත් වැඩ නිසිොකාරව කර දැමීමට database management system එක ම ොකු උදේවක් මවනවා. Ex – Oracle RDBMS MongoDB SQLLite Micrsoft SQL Server Neo4j Postgresql GUI – Graphical User Interface DBMS Client (GUI Application) DATA Developer INSERT UPDATE Application DBMS client (WEB, MOBILE, DESKTOP, GAMES) (Database Management System) DELETE SEARCH Database File Data Model Devloper ට පමනක් මේන මකොටස Data Structure in DBMS - Database Management System MySQL – Table Data Structure id Name Mobile 1 Saman 0712345678 2 Kamal 0772344323 Firebase – JSON Data Structure (JSON – JavaScript Object Notation) {id:”1”,name:”Saman”,mobile:” 0712345678”} {id:”2”,name:”Kamal”,mobile:” 0772344323”} XML – XML Data Structure Extensible Markup Language - XML 1 0712345678 MySQL - DBMS Database 1 Database 2 Database 3 Table 1 Table 2 Table 1 Table 2 Table 1 Table 2 DATA DATA DATA DATA DATA DATA Database Management System එකක් ඇතුමේ database ම ොඩක් තිමෙන්න පුලුවන්. ඒ වමේම එක table ම ොඩක් තිමෙන්න පුලුවන් DBMS ARCHITHECTURE DBMS Architecture represents DBMS DESIGN සර වම කිේමවොත් DBMS එකක තිමෙන design එකක් තමයි DBMS Architecture කිෙන්මන්. DBMS එකක් හදන්න එක එක ක්‍රම තිමෙනවා DBMS ARCHITECTURE Single tier Architecture Multi tier Architecture 1 tier 2 tier 3 tier Architecture Architecture Architecture 1 tier Architecture Client, Server and Database all reside on the same machine DBMS එකකට අවශය හැම components එකක්ම (client, server, database) එක machine එකක තිමෙනවානේ එවැනි concept එකකට 1 tier Architecture එකක් කිෙ ා කිෙනවා. 2 tier Architecture SQL – Structured Query Language මමහිදී database එක හා client, computer එක මවන මවනම තිමෙනවා. මමහිදී client ා කීපමදමනක්ට database එකත් එක්ක සේබන්ද මවන්න පුලුවන්. හැබැයි database එක හා client එක අතර අතරමැදිමෙක් නෑ. ඒ නිසා client සිද්දමවනවා database එකත් එක්ක නුමදනු කරන විදිහ ඉම න න්න. (SQL) 3 tier Architecture (ANSI-SPARC) Client, SQL වමේ database එකත් එක්ක නුමදනු කරන language දැන ැනීම අතයවශය නෑ. ඒ හැමමදෙක්ම server එක දන්නවා (DB එකත් එක්ක නුමදනු කරන විදිහ). මමහිදී client, server, database එක මවන මවනම ඉන්මන්. Clientට database එකත් එක්ක මකලින්ම සේබන්ද මවන්න බෑ. අනිවාර්මෙන්ම client server එකත් එක්ක තමයි සේබන්ද මවන්න ඕමන්. ඒ නිසා client මකමනක් database එකත් නුමදනු කරන ආකාරෙ අනිවාර්මෙන්ම දැන ැනීම අවශෙ නෑ. ANSI-SPARC Architecture ANSI-SPARC Architecture එකටම තමයි Three Schema Architecture Three-Level Architecture කිෙන්මන්. American National ANSI-SPARC නේ මේ ආෙතනෙ විසින් තමයි මේ concept එක Standards හද ා තිමෙන්මන්. මමොකක්හරි විමශේශ database system එකක් use Institute කරන්න තමයි මේ database එක. එමගින් user application එකක් හා physical database එකක් මවන්කර බාවිතා කරන්න පුලුවන් Standards Planning And Requirements Committee External Schema/Level External Level External Level User Application මේ level එමක්දී user මකමනක් Database එකත් එක්ක නුමදනු කරන ආකාරෙ Conceptual Schema/Level Conceptual Level Describe the structure of the database Database එකක architecture එක Database එකක් design කරන්මන් database administrator Design කරන ආකාරෙ විසින් සමහර අවස්තා ව දී software developer design කරනවා Internal Internal Level Physical Data Storage Schema/Level හදා ත්ත database එක hard drive එකක Store කර ා ඒක handle කරන විදිහ DATABASE Data Independence 1. Logical data Independence. Conceptual level එමක් සිදුකරන මවනසක් නිසා External Level එකට බ පාන මදන්නැතුව වැඩකිරීම. (Structure/Entity/Relationship ව මවනසක්. මේවා apply කරන්න ටිකක් අමාරුයි) 2. Physical data Independence. Internal level එමක් සිදුකරන මවනසක් නිසා Conceptual හා External level ව ට බ පාන්නැතුව වැඩ කිරීම ෙේකිසි level එකක මමොකක්හරි මවනසක් සිද්දවුමනොත් ඒමක් බ පෑම අනිත් level ව ට බාමනොදීම තමයි Data Independence කිෙන්මන් HOW TO UNINSTALL MY SQL CORRECTLY FROM COMPUTER? Mysql80 එක stop කරන්න ඕමන්. (right click  stop) Control panel එකට ගිහින් mysql නමින් තිමෙන හැම එකක්ම uninstall කරන්න ඕමන්. C:\Program File\MySql (delete කරන්න) C:\Program Files (x86)\MySql (delete කරන්න) C:\ProgramData\MySql C:\Users\ \AppData\Roaming\MySql C:\Users\ \sc Delete MySQL80 (cmd එමක් type කරන්න) How to install MySQL Correctly for a Mac Computer? Software එක install කරන්න කලින් password එක මදන්න. Software එක double click කර ා open කරන්න. Continue මදන්න. Use strong password encryption මතෝර ා next මදන්න. Strong password එකක් දී ා start MySQL Server once the installation is complete එකට tic එක දා ා finish කරන්න. How to install MySQL Correctly for a Windows Computer? Download වලින් software එක double click කර ා open කරන්න. Full එක select කර ා next කරන්න. Ggg How to create database from work bench? Navigator එමක් schemas එක select කරන්න. Blank area එක right click කර create schemas මදන්න. Name එකට database එකට කැමති නමක් දාන්න. පස්මසේ apply කරන්න. ඊට පස්මසේ එන එකටත් apply දී finish කරන්න. Schemas ෙටමත් හදපු db එක මේන්න න්නවා. Constraints Table එකක තිමෙන data අපි use කරද්දී තිමෙන rules ව ට තමයි constraints කිෙන්මන්. Ex – NOT NULL/ Auto Increments/ Unique/ Defaults Database එකක table හදද්දී එක එක rules තිමෙනවා. අපි constraints එක්ක වැඩ කර යුතුයි. අපි constraints එක්ක වැඩ කමර් නැත්තන් ෙේ කිසි මව ාවක error එනවා. id product qty price 1 iphone 5 50000 2 iphone 5 60000 3 iphone 5 60000 4 iphone 5 60000 NOT NULL මේ constraints එමකන් කරන්මන් ඒ cell එමක් value එකක් අනිවාමෙන්ම තිමෙන්ම ඕමන් කිෙ ා. (0 කිෙන්මනත් value එකක්) Default මේ constraints එමක්දී කරන්මන් අමේ column එකට value එකක් නැත්තන් ඒ column එකට default value එකක් set කිරීමයි. Unique කිසිමසේත්ම duplicate මවන්නෑ. Table row Auto Increment මේමකදී මවන්මන් ෙේ කිසි table එකක unquly අදුර න්න පුලුවන් column එකක් නැත්තන් අපිට පුලුවන් id වමේ uniqu මවන column එකක් හදන්න එකට අපි value add කරන එක කරදර නිසා auto increment කිෙන constrents එක දී ා අංක 1 ඉදන් පිලිමව ට number add මවන්න මදන්න පුලුවන්. ඒ පිලිමව ට number add කරන්මන් එක විසින්. Keys 1. Super key 2. Candidate key nic name mobile user country dob 3. Primary key email 4. Alternate key 5. Foreign key 6. Composite key 7. Compound key 8. Surrogate key Tuple – table එකක තිමෙන row එකකට tuple එකක් කිෙනවා. Attribute – table එමක් තිමෙන column එකකට column එකක් කිෙනවා. Key – table එකක් row එකක් uniquely identify කරන්න පුලුවන් මකමනක්ට. Super key Rows uniquely identify කර න්න භාවිතා කරන ඒවට. ඒක column එකක් මහෝ column කීපෙක එකතුවක් විෙ හැකිෙ. (nic/ mobile/ email/ nic, name/ email, mobile/ nic, email) Candidate key Super key ව ට සුදුසු නමුත් ඊටත් වඩා මහොද ඒවට මේකට අදා මේ. Primary key ෙේ කිසි table එකක සෑම row එකක්ම uniquely identify කරන්න බාවිතා කරන column එක primary එක කිෙනවා. මේක candidate key ව ට වඩා සුදුසු ඒවා විදිහට න්න පුලුවන්. Alternate key candidate keys වලින් primary key එකක් මතෝර ත් පසු ඉතුරු මවන අනිත් column ව ට alternate key එකක් කිෙනවා. Foreign key මවන table එකකින් ආපු column එකක්. ඒ column එක එොට අයිති table එමක් primary key එක මේ. Composite key මේ key එක group විදිහට ෙන්මන්. Column කීපෙක එකතුවක් (NIC,Name) Compound key මමම key එකද composite key එක වමේ column group එකක් මේ. ඒත් මේ group එකට foreign key එකක් ඇතු ත් මේ. surrogate key අමේ requirements ව ට අනුව table එක design කරද්දී primary key එකක් විදිහට න්න column එකක් නැත්තන් ඒ මවනුවට අපි අලුතින් හදන key එක තමයි (auto increment මවන්න දාන්මන් මේ වමේ එකට) developer කෙකෙක් DBMS එෙක් එක්ෙ සම්භන්ද කලෙ ආොරය (DBMS Client) DBMS (Database Management System) MySQL Server db1 db2 db3 db4 db5 My SQL Server Username Password Port DBMS Client MySQL Workbench Heidi SQL Navicat client අමේ dbms එක ඇතුමේ ම ොඩක් database තිමෙන්න පුලුවන්. හැබැයි developer මකමනක්ට මකලින්ම මේ data ව ට access කරන්න බෑ. Developer මකමනක්ට database එකට access කරන්නනේ අනිවාමෙන්ම dbms client මකමනක්ව භාවිතා කරන්න සිද්ද මවනවා. Dbms client මකමනක් හරහා විතරයි developer මකමනක්ට database එකක් බ න්න පුලුවන් මවන්මන්. Dbms client මකමනක් හරහා dbms එක සම සේභන්ද වන විට අමේ mysql server එකට username, password එක හා port එක අනිවාමෙන්ම සදහන් කර යුතුයි. My SQL workbench එකෙන් connection එෙක් හදෙ විදිහ. 1 Click “+” mark 4 2 Set name Give Db password and Click ok button 3 Click store in vault… 5 Click ok button Our new connection Connection එෙක් delete ෙරෙ ආොරය. Connection එක උඩ right click කරන්න. click මේක click කමරොත් අපි හද ා තිමෙන ඔක්මකොම connection ටික delete මවනවා HeidiSQL ල඼ connection එෙක් හදෙ විදිහ. 2 Open කරන්නනේ db එකට දුන්න Set name password එක දී ා 3 1 open මදන්න. Click new 4 Heidi SQL ල඼ connection එෙක් delete ෙරෙ විදිහ. 1 3 2 Yes මදන්න Connection එක උඩ right click කර ා delete එක click කරන්න. Haidi SQL ලලින් db එෙක් හදෙ විදිහ. 2 1 Db එකට නමක් දී ා ok කරන්න. Haidi SQL ලලින් table එෙක් හදෙ විදිහ. Table name Column name 1 Click save Application එෙක් DBMS එෙක් එක්ෙ සම්භන්ද කලෙ ආොරය Device DBMS (Database Management System) MySQL Server db1 db2 db3 db4 db5 Connector Un: root, pw:, port : 3306 Web Android IOS Descktop application application (java/ application application Game (C#) (PHP) kotlin) (swift) (java) Application + DBMS = samelocation (Localhost) Application + DBMS = difference location (remote) SQL – Structured Query Language DBMS (My SQL server) – group of databases/ schemas Database/ Schemas – group of table Table – group of data Data – details which we enter to a system Query – a sentence written in SQL INSERT – save data in database UPDATE – change saved data from database DELETE – delete saved data from database SEARCH/ select – find saved data from database MySQL Data Type Date and String Numeric Time Data Data type Data Type Type අමේ database එමක්දී භාවිතා කරන data ව එක එක ආකාර ව ට data type කිෙනවා. String data types Letters, numbers, symbols හා special characters මේවාට අයිතිමේ. Data type Description CHAR A FIXED length string (can contain letters, numbers, and special characters). The size parameter specified the column length in characters – Can be from 0 to 255. default is 1 VARCHAR(size) A VARIABLE length string (can contain letters, numbers, and special characters). The size parameter specifies the maximum column length in characters – can be from 0 to 65535 BINARY(size) Equal to CHAR(), but strong binary byte strings. The size parameter specifies the column length in bytes. Default is 1 TEXT(size) Hold a string with a maximum length of 65,535 bytes. NUMARIC DATA TYPE මමම data type එක ෙටමත් numbers හා දශම සංකයා ලිෙන්න පුලුවන්. Data type Description BIT(size) A bit-value type. The number of bite per value is specified in size. The size parameter can hold a value from 1 to 64. the default value for size is 1. BOOL Zero is considered as false, nonzero values are considered as true. BOOLEAN Equal to BOOL. INT(size) A medium integer. The size parameter specifies the maximum display width (which is 255). INTEGER(size) Equal to INT(size). FLOAT(p) A floating point number. MySQL user the p value to determine whether to use FLOAT or DOUBLE for the resulting data type. If p is from 0 to 24, the data type becomes FLOAT(). If p is 25 to 53, the data type become DOUBLE(). DOUBLE(size, d) A normal-size floating point number of digits is specified in size. The number of digits after the decimal point is specified in the d parameter. Date and Time Data Types Date, years, month, time එකක් දාන්න තමයි අපි මේ data type එක භාවිතා කරන්මන්. Data type Description DATE A date. Format: YYYY-MM-DD. The supported range is from ‘1000-01-01’ TO ‘9999-12-31’ DATETIME(fsp) A date and time combination. Format: YYYY-MM- DD hh:mm:ss. The supported range is from ‘1000-01-01 00:00:00’ to ‘9999-12-31 23:59:59’ TIMESTAMP(fsp) A timestamp. TIMESTAMP values are stored as the number of seconds since the Unix epoch (‘1970-01-01 00:00:00’ UTC). Format: YYYY-MM- DD hh:mm:ss. The supported range is from ‘1970-01-01 00:00:01’ UTC to ‘2038-01-09 03:14:07’ UTC TIME(fsp) A time. Format: hh:mm:ss. The supported range is from ‘-838:59:59’ to ‘838:59:59’ YEAR A year in four-digit format: YYYY. Values allowed in four-digit format: 1901 to 2155, and 0000 MySQL 8.0 does not support year in two-digit format Practical db-7 කිෙ ා database එකක් හදන්න. පහත සදහන් table එක create කරන්න. Table name – student, Id – INT, student_name – VARCHAR(50), subject – VARCHAR(50), marks - INT id student_name subject marks 1 kasun maths 90 2 hashini ICT 80 3 pasan science 86 4 shehan english 78 INSERT Query INSERT INTO `table_name` (`column_1`,`column_2`,`column_3`,`column_4`) VALUES (‘value_1’,’value_2’,’value_3’,’value_4’); UPDATE Query UPDATE `table_name` SET `column_1` = ‘value_1’ WHERE `column_2` = ‘value_2’; DELETE Query DELETE FROM `table_name` WHERE `column_1` = ‘value_1’; SEARCH Query “*” Mark එමකන් කිෙන්මන් ඔක්මකොම නැත්තන් all කිෙන්න. SELECT * FROM `table_name`; SELECT `column_1`,`column_2` FROM `table_name` WHERE `column_3` = ‘value_3’; සාමානයමෙන් අපි query එකක් කිෙවන්මන් අ සිට මු ට. SQL Command SQL commands කිෙන්මන් instructions ම තමයි. අමේ db එකක් සම communicate කරන්න තමයි මේක භාවිතා කරන්මන්. SQL commands භාවිතමෙන් specific task එකක්. Function එකක් මහෝ query එකක් ලිෙන්න පුලුවන්. SQL Commands DDL DQL DML TCL DCL SQL Commands DDL DML DCL TCL DQL Create Insert Grant Commit Select Drop Update Revoke Rollback Alter Delete Save point Truncate Data Definition Language (DDL) Table එකක් structure එක permanently මවනස් කරන්න DDL භාවිතා කරනවා. CREATE ALTER DROP TRANCATE CREATE අපිට අලුතින් table එකක් මහෝ database එකක් හදන්න පුලුවන්. ALTER Table එකට අලුතින් column එකක් add කරන්න පුලුවන්. DROP Table එකක් මහෝ db එකක් permanently අයින් කරන්න පුලුවන් TRANCATE Db එකක් rows column ඔක්ක්මකොම අයින් කරන්න පුලුවන්. Data Manipulation Language (DML) DML command එකකින් db එකක් මවනස් කරන්න පුලුවන්. Permanently සිද්ද මවන්නෑ. අපිට ඒක undo කරන්න පුලුවන්. INSERT UPDATE DELETE INSERT Db එකට අලුතින් data add කරන්න පුලුවන්. UPDATE තිමෙන data එකක් මවනස් කරන්න පුලුවන්. DELETE තිමෙන data එකක් අයින් කරන්න පුලුවන්. Data Control Language (DCL) Db එකක users ට access privileges බාමදන්න හා බා න්න භාවිතා කරයි. GRANT REVOLKE GRANT Privileges බාමදන එක REVOLKE Privileges නැවත බා න්න එක. Transaction Control Language (TCL) අමේ db එමක් නුමදනු contrail කරන්න භාවිතා කරයි. මේවා DML එක්ක භාවිතා කරයි COMMIT ROLLBACK SAVEPOINT COMMIT අමේ db එමක් සිෙලුම transections save කරයි. ROLLBACK Db එමක් save මව ා නැති නුමදනු undo කරනවා. SAVEPOINT Save කරපු transaction එකතැනකට අර න්නවා. Data Query Language (DQL) SELECT Db එකක ඇති data බා න්න පුලුවන් Difference between DDL & DML DDL CREATE It is used to create a new db and its objects as table, view, function, stored procedure, triggers, etc. DROP It is used to delete the db and its objects, including structures, from the server permanently. ALTER Its used to update the db structure by modifying the characteristics of an existing attribute or adding new attributes. RENAME This command renames the content in the db or table. Users of DDL Commands Table creation Table modification Table deletion Making indexes View creation Data Manipulation Language (DML) SELECT This command is used to extract information from a table. INSERT Its is a SQL query that allows us to add a tables row. UPDATE This command is used to alter to modify the contents of a table. DELETE This command is used to delete records from a table, either individually or in groups. Uses of DML Commands Data insertion Data updating Data deletion Data retrieval Filtering data 1. Db10 කිෙ ා database එකක් හද ා පහත data ටික insert query එක මගින් insert කරන්න. stud_id f_name l_name nic address age subject marks S001 Sandun Perera 957414152V 50,1st lane, kottawa 28 Maths 85 S002 Amal Perera 981524215V 21, soyza lane, 25 ICT 75 colombo 5 S003 Isuru Gayan 971542412V 521, colombo road, 26 Science 91 pilimathalawa S004 Thilan Kavinda 992121245V 92, 2nd cross lane, 24 Commerce 75 kandy S005 Sanduni Perera 991254785V 62, upper road, 24 ICT 90 gampaha S006 Isuru Kalhara 974514152V 25, 1st cross lane, 25 English 60 piliyandala S007 Sandun Pansilu 971524212V 22, 1st cross lane, 26 Maths 81 nittambuwa S008 Nadun Silva 991254121V 10, 2nd lane, 24 ICT 90 kurunegala S009 Kasun Kalhara 941525452V 11, colombo road, 27 English 71 kegalle S010 Kasun Bandara 981542152V 157/2, cross lane, 25 ICT 77 kurunegala 2. stud_id එක S001 මේ marks column එක 95ට update කරන්න. 3. f_name එක thilan කිෙන student මේ subject එක english හා marks 50 කිෙ ා update කරන්න. 4. S006 කිෙන studentමේ f_name එක pasan කිෙ ා හා l_name එක nimesh කිෙ ා subject එක ICT හා marks 79 කිෙ ා update කරන්න. 5. stud_id එක S010 student ම record එක delete කරන්න. 6. Student_details කිෙන table එමක් ඔක්මකොම details ටික search කර ා අරන් මදන්න. 7. Stud_id එක S002 කිෙන studentමේ f_name, l_name, nic, age search කරන්න. 8. Student_details table එමක් f_name, l_name, nic එක search කරන්න. HeidiSQL ලලින් primarykey එෙ දාෙ විදිහ 1. INSERT INTO `student_details` (`stud_id`,`f_name`,`l_name`,`nic`,`address`,`age`,`subject`,`marks`) VALUES ('S010','Kasun','Bandara','981542152V','157/2, cross lane, kurunegala','25','ICT','77'); 2. UPDATE `student_details` SET `marks` = ‘95’ WHERE `stud_id` = ‘S001’; 3. UPDATE `student_details` SET `subject` = 'english', `marks` = '50' WHERE `f_name` = ‘thilan'; 4. UPDATE `student_details` SET `f_name`='Pasan',`l_name`='Nimesh',`subject`='ICT',`marks`='79' WHERE `stud_id`='S006'; 5. DELETE FROM `student_details` WHERE `stud_id` = 'S010'; 6. SELECT * FROM `student_details`; 7. SELECT `f_name`, `l_name`, `nic`, `age` FROM `student_details` WHERE `stud_id` = 'S002'; 8. SELECT `f_name`, `l_name`, `nic`, `age` FROM `student_details`; CREATE 1. Create Database CREATE DATABASE `database_name`; 2. Create Table CREATE TABLE `table_name` ( CREATE TABLE `table_name` ( `column_name1` Data Type NOT NULL, `column_name1` Data Type PRIMARY KEY AUTO_INCREMENT, `column_name2` Data Type NOT NULL, `column_name2` Data Type NOT NULL UNIQE, `column_name3` Data_Type NULL `column_name3` Data_Type NULL ); ); ALTER / RENAME My_shop db එක තු ඇති employee table එක customer ම ස change කරන්න. ALTER TABLE `old_table_name`  Table name change RENAME TO `new_table_name`; ALTER TABLE `table_name` CHANGE `old_column_name` `new_column_name` DATA TYPE(Data Length); TRUNCATE TRUNCATE TABLE `table_name` ; DROP DROP TABLE IF EXISTS DROP TABLE IF EXISTS `table_name`; `db_name`.`table_name`; my_shop employee Unique INT VARCHAR VARCHAR Auto_Increment VARCHAR INT NOT NULL NOT NULL VARCHAR id name age mobile address gender 1 Alex 35 0771263259 92,2nd cross Male lane, kelaniya 2 Kumari 28 0785239605 62, upper Female road, dematagoda 3 Wathsala 30 0778963005 25, 1st cross Female lane, peliyagoda 4 Saman 32 0720589630 Havelock Male lane, colombo 5 1. Db , table එක query එකක් මගින් create කරන්න. 2. Data ටික query එකක් මගින් insert කරන්න. 3. My_shop db එක තු ඇති employee table එක customer ම ස change කරන්න. 4. Customer table එමක් ඇති age column එක nic ම ස change කරන්න. 5. my_shop db එක තු ඇති customer table එමක් ඇති සිෙලුම data rows clear කරන්න. 6. my_shop db එක තු ඇති customer table එක remove කරන්න. 7. my_shop db එක remove කරන්න. 1. CREATE DATABABSE `my_shop`; CREATE TABLE IF NOT EXISTS `my_shop`.`employee` ( `id` INT AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR(75), `age` INT, `mobile` VARCHAR(15) UNIQUE, `address` VARCHAR(250), `gender` VARCHAR(10) ); 2. INSERT INTO `my_shop`.`employee` (`name`,`age`,`mobile`,`address`,`gender`) VALUES ('Saman','32','0720589630','Havelock lane, colombo 5','male'); 3. ALTER TABLE `employee` RENAME TO `customer`; 4. ALTER TABLE `customer` CHANGE `age` `nic` VARCHAR(15); 5. TRUNCATE TABLE `customer`; 6. DROP TABLE IF EXISTS `my_shop`.`customer`; 7. DROP DATABASE IF EXISTS `my_shop`; SQL Operators & Conditions Operators Description AND TRUE if all conditions separated by AND is TRUE OR TRUE if any of the conditions separated by OR is TRUE NOT Display a record if the condition(s) is NOT TRUE BETWEEN TRUE if the the operand is within the range of comparisons LIKE TRUE if the operand matches a pattern Db name – my_shop Table name – customer id name Age Mobile Email City 1 Nimal 25 0789630258 nimal@gmail Kandy.com 2 Thisara 28 0785239605 thisara@gma Colombo il.com 3 Nimal 30 0778963005 nimal01@gm Matara ail.com 4 Saman 32 0720589630 saman@gma Gampaha il.com 5 Kasun 16 0778956200 kasun@gmai Kandy l.com 6 Sanduni 23 0745896305 sanduni@ga Kurunegala mil.com 7 Kasun 25 0770963005 kasun099@g Colombo mail.com AND AND එක භාවිතා මකොට output එකක් බා ැනීමට නේ ස කා බ න සිෙලුම conditions සතය විෙ යුතුමේ. 1. Customer table එමක් ඇති kandy ව සිටින nimalව searche කර ා න්න. 2. Customer table එමක් ඇති city එක matara සිටින age එක 30 වන name එක nimalව search කරන්න. OR ස කා බ න condition අතරින් ස කා බ න conditionවලින් අඩුම එකක් මහෝ සතය වීම ප්‍රමානවත් මේ. 3. Age එක 25මහෝ city එක matara වන අෙ search කරන්න. 4. City එක colombo වන මහෝ email එක [email protected] වන customers මේ details ටික search කරන්න. 5. Name එක saman වන මහෝ age එක 25 වන මහෝ city එක gampaha වන customers මේ details ටික search කරන්න. NOT NOT එක තුලින් output එකක් බා න්නනේ සදහන් කරන මද් හැර අමනක් සිෙලුම මද්වේ මේතුලින් display කර ත හැක. මමහිදී නැත ෙන අර්තෙ අදහස් මකමර්. 6. City එක kandy මනොවන සිෙලුම customers ා search කර ා න්න. 7. City එක colombo හා matara මනොවන සිෙලුම customers ා search කරන්න. BETWEEN ෙේකිසි data range එකක් තු output එකක් බා ැනීමට නේ BETWEEN operator එක භාවිතා කරයි. 8. Age එක 20 හා 30 අතර customers මේ details ටික search කර ා න්න. 9. Age එක 25 ත් 30ත් අතර මනොවන customers මේ details ටික න්න. LIKE - Wildcard LIKE Operator Description WHERE CustomerName LIKE ‘a%’ Find any values that start with ‘a’ WHERE CustomerName LIKE ‘%a’ Find any values that end with “a” WHERE CustomerName LIKE ‘%or%’ Find any values that have “or” in any position WHERE CustomerName LIKE ‘_r%’ Find any values that have “r” in the second position WHERE CustomerName LIKE ‘a_%’ Find any values that start with “a” and are at least 2 characters in length WHERE CustomerName LIKE ‘a__%’ Find any values that start with “a” and are at least 3 characters in length WHERE CustomerName LIKE ‘a%O’ Find any values that start with “a” and ends with “o” 10. Name එක n අකුමරන් පටන් න්න customers මේ details ටික search කරන්න. 11. Mobile number එක 0 වලින් අවසන් වන customers ව search කරන්න. 12. Mobile number එමක් කවර මහෝ තැනක 63 ම ස ඇත්නේ එෙ search කරන්න. 13. Name එක s අකුමරන් start වන හා n අකුමරන් end වන customers ව search කරන්න. 14. Name එමක් මදමවනි letter එක h වන customers ව search කරන්න. 1. SELECT * FROM `my_shop`.`customer` WHERE `name`='Nimal' AND `city`='kandy'; 2. SELECT * FROM `my_shop`.`customer` WHERE `name`='Nimal' AND `age`='30' AND `city`='matara'; 3. SELECT * FROM `my_shop`.`customer` WHERE `age`='25' OR `city`='matara'; 4. SELECT * FROM `my_shop`.`customer` WHERE `city`='colombo' OR `email`='[email protected]'; 5. SELECT * FROM `my_shop`.`customer` WHERE `name`='saman' OR `age`='25' OR `city`='gampaha'; 6. SELECT * FROM `my_shop`.`customer` WHERE NOT `city`='kandy'; 7. SELECT * FROM `my_shop`.`customer` WHERE NOT `city`='colombo' AND NOT `city`='matara'; 8. SELECT * FROM `my_shop`.`customer` WHERE `age` BETWEEN '20' AND '30'; 9. SELECT * FROM `my_shop`.`customer` WHERE `age` NOT BETWEEN '25' AND '30'; 10. SELECT * FROM `my_shop`.`customer` WHERE `name` LIKE 'n%'; 11. SELECT * FROM `my_shop`.`customer` WHERE `mobile` LIKE '%0'; 12. SELECT * FROM `my_shop`.`customer` WHERE `mobile` LIKE '%63%'; 13. SELECT * FROM `my_shop`.`customer` WHERE `name` LIKE 's%n'; 14. SELECT * FROM `my_shop`.`customer` WHERE `name` LIKE '_h%';

Tags

database management system DBMS architecture data structures computer science
Use Quizgecko on...
Browser
Browser