0% found this document useful (0 votes)
7 views34 pages

Csa 2

The document provides an overview of databases, data hierarchy, and SQL, explaining the difference between data and information, as well as the structure of databases including tables, records, and fields. It discusses the advantages and limitations of Database Management Systems (DBMS), and introduces SQL as a language for managing and manipulating data within databases. Additionally, it covers types of databases, including hierarchical, network, and relational models, along with their respective benefits and drawbacks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
7 views34 pages

Csa 2

The document provides an overview of databases, data hierarchy, and SQL, explaining the difference between data and information, as well as the structure of databases including tables, records, and fields. It discusses the advantages and limitations of Database Management Systems (DBMS), and introduces SQL as a language for managing and manipulating data within databases. Additionally, it covers types of databases, including hierarchical, network, and relational models, along with their respective benefits and drawbacks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 34
Database and SQL. INTRODUCTION TRTRODUCTION Data : They are raw or known facts, i.e. the data that has not been processed. For example, data of the ages of students in a class. Information : Processed data is called information. For example, we find from the data of the age of students in a class, how many students are of age 18. The result we obtain is information. Practically everything we do generates data. Our ancestors also needed to record such data. When there were floods, marks were made on walls in, different places, to indicate the level to which the water had risen in that area. In today’s complex world, with so much data being generated due to various type of financial and non-financial transactions, we need means to record this information in a meaningful manner, so that ‘we can retrieve it later with ease. Database A database.is a collection of data that is related in some way. A list of students enrolled for the commerce stream, the list of names, addresses and telephone numbers in atelephone directory etc are all examples of databases. A database can be compared to a filing cabinet which contains many files. The files are tables containing data. The size ofa database can be very large and can have varying levels of complexity. While today most databases are maintained on computers, some of them may be manually maintained. HIERARCHY OF DATA Character : Consists of letters (A-Z), digits (0-9) and special characters (-, +, * etc). Field(Column) : Is 4 collection of related characters. e.g. name, age etc. Record(Row) : Is a collection of related fields. eg. all the information of a student i.e. his name, age, address, roll number etc. is a record. File(Table ) : A collection of related records is called a file. Databaes, + A collection of one or more related Files is called a Database. Note: In SOL snore common to ealla Red ra Chinn a record as a Row and a File aca Table. Pye ee NOON, (Computer Systems and Applications cry, 8.Cam oor ay, © DBMS. uter based system) that enables ion of programs (comp thes, A ett inaintan a databese, I used to define, ene mane yt the database for various applications. It provides info ess restrict ag, ire cual capabilities, The DBMS also enforces necessary soeess Testrictions ang monsires fr order to protect the database. Various (pes of control systems wf! measures in of inues to function properly. They include ” ke sure that the database contint ine gem" Sealy stem - Concurency contol system Rreoweny contol sem) system - inden) . A view is how ‘abase 'n, dot arse ryan few te dom the user. This enal 7 dat: . Us and it inereases security, as certain users will not be able to see data which thy meant to see. Advantages of DBMS 1, Redundancy is controlled. 2. Unauthorized access is restricted. 3. Provides multiple user interfaces, 4. Enforces integrity constraints, 5. Provides backup and recovery of data, Limitations of DBMS 1. Uses extra computer time and resources, 2. Itis expensive to install new systems, 3. Requires well qualified and expert personnel to operate the system, & Fitisnot designed for concurrent access to many users it will be of little use, % Atthotly of ownership rights over the data have to be fixed, so as to der who is eligible for using the data, ‘termine RECORD RELATIONSHIPS To make it easy for the end user whe fotoningate reatoneie ‘ae 10 use the database for various Purposes, the ~ One : Here: one Patent record is associ it One (ocr in a hospital wl take care patient With only one child record, ~ One: Here two or. many doctors wit More parent Tecords are associated wit i ° ‘ be attending to a single Patient, with one child Tecord, e.g. Here two or Teconts More parent reco ‘ . eres pase Mere doctors yh be a Tecords are associated with two or more child Pétionts wl be tending to two i . : ‘Ssoddtted with dierent doctors,” MO Patients, hence bills of loctors, Database and SQL Hierarchical model 5 a) In this model the di \e differe A parent record can have sores are rela . cal ted throu; 7 A Barn record can have many child records, ‘ough invened tree ike structures. ave only b) Ituses the . ©) Ina hictarchical dee one : many relationships, For example, under Pres nerds conta under in groups of pare a A and B received ae Department (parent) ‘vould be stored the orders required for the order A ai patent (child), under that would be the Skills thateral required we end the date of delivery (ci, and for order the child would be the employ Tequired and the date of delivery (child), another ‘Aithough this model ern ech onder. , anothe many Sop ce, as Been widely used, itis olen consiceed nt autoble for telationships. structure is inflexible and is not suitable for complex Example of Hierarchical Da d Tt~— Skills Dateof | - Material Machines Date of Required delivery Required Required delivery Advantages 1, The structure is simple to construct and operate. 2. As the batch operations like payroll are done at maximum speed they permit day to day structured operations rapidly. Disadvantages cannot be handled in this model. 1 Many to many relationships 2. Its structure is quite rigid and hence a resulting in making anew database. } cence parent record is complex as the entire branch of child records Deleng win thas tobe Bist deleted 4. Adhoc queries are not supported. can have many child dding a field is very complicated often 3. records and a child record can fb) Ituses the many : Mi rie ne P amos Sse an TEINS TY eam a packs of the Hierarchy, resses some of the draw! cm ag Hence this model ager snueries Ond relationships than a ts. more compl Dossy, fe ne ita it is very c ‘ ee k as its limitations, as I" FY comple Net ers pase to be familiar with the structure Me Tse reached and how they got there. i ture, it would affect the api, tog, e ° toneate datab ack of where they have ih 1 tany change is to be made to the interacts with the database. Example of Network Database Teacher 2 SudentB Student C Advantages 1. Ithasa higher level of flexibility as compared to Hierarchical Database. 2. They are ideal for handling many to many relationships. 3. Complex data relationships can be represented more effectively. Disadvantages 1. The database structure is difficult to change. 2. Operation and maintenance of this structure is quite complicated. 3. ‘There is lack of structural independence, relationships cannot existing database easily, De added tot RELATIONAL DATABASE MANAGEMENT SYSTEMS(RDBMS) 1. The Relational Database model was : Proposed b However, the frst commercial system appested oni. 3isee . : In this model, unlike the Hierarchical and Netwo! Mr. Codd of IBM i nly in 1981-82, nism tk models, there are No physica ‘often replaced hi i a0 ear bo tea hierarchical databases and netwott tstand and use, even though they ar increase, - . al in aa inefficiencies of relationd times, have been outweighed challen : . dress he bY Object Databases, which databace, UleCtrelational impedance ) Database and SOL, 1 noe tae reams organizations the Hierarchical sr nework Databases a business systems and itis the found ones Widely implemented model in modem Relate Data 4ees {or a Relational DBMS, also called as Codd’s Rule. A acknowledged as a fully operational RDBMS, that satisfies at least six of these rules is shock and Suppiene HNentory database given below, which consists of the tables of information from both tabiss ar mes Colum Is the same In both tables sve can cba time, Stock Table stockid | supp id | stock name _| clstock 1138 901 Dove Soap 245 1145 002 Colgate 153 1167 003, Nirma 110 Supplier table supp_id | Supp_name | Phone_no 001 Manu & Co. | 9821066723 002 Raju & Co, 9912456023 003 | Hiral & Co, | 9983457120 PRIMARY KEY A column in the table that uniquely identifies each row in that table is called the primary key. In the above example stock id in the stock table can be the primary key. CANDIDATE KEY Ina table there could be more than one column that uniquely identifies a row in the table. Then such columns are called candidate keys. From among the candidate keys, we can choose one to be the primary Key, or a combination of them to be the primary key. In the above stock table stock_id and supp_id are candidate keys. Any one of them can be selected as the primary key. FOREIGN KEY - - _ It is a column in one table, whose value matches with the primary key in another. table. A foreign key establishes a relationship, or constraint, between two tables, If above les, stock id is the primary Key in the stock table and supp_fd is the iy as ‘supplier table. The supp_id column in the stock table is the foreign key, is ke nite eee app id key which i the primary key in the supplier able. s associal ‘supp_t . STRUCTURED Y LANGUAGE(SQL) Introduction i ct with data kept in a ge used to manage and mr Smpliy the method of is a computer langual to organize § aty . SQL designed not Fist to reorganize data within the dab ‘baring information from the Gata, asa fourth generation language (4GL). been cat rized rocedural Query | roced im database (ta0le). ee sia te te end ents, ch oC gn wal be obened’ | Fogram does. 25 the language defines both 1” pro! over WAR nethod to be followed to obtain the same. In so) database engine, to decide the bet 7 | — posers eed AgPICaEOTS TY. Bay, 1 wv Language 7 s on janguage. 25 the user only gives 0) Jithout having to wo; vel] the PF ; e to the ‘component of the os cone ba is te ro oun fom the ‘able. THE SQL statements merely ga input and output. but not the procedure. . “Ta Hence with SQL we cannot write complete applications. ‘SQL Statements . . ‘They can be proadly categorized into the following 1, Data Definition DL) ‘This language is used by the designers and programmers of the database to ;, the content and the structure of the database. It is used to indicate the physica] Re, the con te Held names, their types etc. and also the record relatio SMe, CREATE, ALTER, and DROP statements. te 2. Data Manipulation Language (DML) _Tis language & used primariy for data manipulation and processin ting a, arranging the data, deleting the data and displaying id a in e database and receives Tequired ta ee INSERT, DELETE statements the repos. @.8. SELECT, Upp; 3, Data Control Language(DCL) ~ This is used for controlling the data and access seoulyisunsand suite sous the dutdhece Ep GRANT Bee es tabase. Eg GRANT, REVOKE sites » REVOKE statemens en, 4 Samreeon Conta Statecoents ese statements are used to handle transactions. They are essen . tially a group q DML statements executed rollbat 7 together as unit temsecons Eg COMMIT and ROLLBACK saieremee 4 © Besin, end ents. : x ‘Answer the following : Whats the hierarchy of data? Today, to would be database has become an integral part of our life. Most of the tasks that we d be ossible without it, Banks, universities, and libraries are examples ni . , ; of oni don hich rely on databases. Further on the internet, search engines, online ‘Rnames, would not be possible without the use of a database. DATABASE SERVER = 2 database that is implemented and interfaced on a computer i called a dauabase One of the fastest SQL database servers currently in the market is the MySQL server, which is developed by T.c.X. DataKonsultAB. It is available free for the general public for private and commercial use, and can be downloaded from http/dev.mysql.com/downloads, Features 1, Itcan handle an unlimited number of users simultaneously. 2. 5,00,00,000 + records can be easily handled. 3. Has one of the fastest execution speeds in the market. 4. Simple and efficient user privilege system. DATABASE A database in MySQL contains one or more tables. Database dean ify the of Each MySQL table consists of rows ns, The columns specify the type ‘whereas rows contain ne meaual Te example the name oae ‘sohmats ‘coal eos identification), ename (employee name), age. salary, city, iad be empid Sine of birth) exc. SUV RC —Com Spe 8 AL GEV) meanOrs TY Be Computer Systems and APP! wre ¥ Jumns I M : ving Names To Database, Table And Columns In The Tabte Rules For OvInE ye maximum 64 characters ong. rd such as USE, SELECT etc. 1, Thoname used in any keywo! me cannot contain any 2 ese names should be unique, Table names should be unique in «, 3. Dartotumn names should be Uniaue in the table. ty ame used should contain only Alphabets, Digits and Ung, Preferably the ni ‘and should not contain any blanks. DATA TYPES Data type is a constraint that is placed 0! be stored in that column. ‘MySQL supports three categ! Numeric and Date/Time. Character/String Data Type Data that cannot be used for mathematical calculations and manipulation, ascharacter data, For example Names, Addresses etc. ate To store such data the following data types can be used. 1, CHAR (width). Here the data is stored as fixed length strings. Its maxi i: 256 bytes, Comparison and sorting of CHAR are case insensitive. SRT en eg char(i0) has the capacity to store 10 charact , “ 4 characters it will use the full 10 bytes. ers. Even if you 2, VARCHAR(width). Here the data.is stored i “ v as variable | + anys athe se ofthe data placed in ite lso uses an et not right padded with spaces. Its maximum length is 65,535 bytes Cee 3). na specific column to limit the va, ories of data types, nan’ eg. varchar(20) has the capacity to st iicshiaed nose a tore 20 characters. If we store ‘Zina’, it wa Note : The data stored it * Ai in both CHAR and VARCHAR when compared are no; ‘TEXT. It is commonh “= ly used to store I it there the minnie large strings. It stores a vari is case insensitive, {65,535 bytes (64 KB). Compaiison rentison baabieahal , ting of such MEDIUMTEXT. It can it Ler721506MB) larger strings than Test type » The maximum se ¢ LONGTEXT, | ' It can store matimum szeis 4.29.49 6 cre oe St 29,49,67,295(4 GB) gS Such as emails . ) and XML docum; ents. The Ie Grae din aloyay DP for Y column is stor; bigint) and ac column. They Storing only numbes ’ can be divided into imeze ecenay ‘ Ppa the can OPE 4 data PO the use of dep "pe(decim; a ES While factional deg we Integer de ue eee eS (float, double Introduction to MySQL Th wre store : ' so e following t. il + 8 table illustrates the integer data types and range of values they can Acceptable Range of val SMALLINT | | signed : -32, 768 to 32, 767 mane “= wee unsigned : 0 to 65,53: BIGINT Signed: 93, aye 47,75, 807 “unsigned: 0 to 1, 84, 46, 74, 40, Od, 46, 74, 40. 73, 70, 95, 51, 61: UNSIGNED : means cannot be negative a If we write amallint , 65535. — Note : A i « eg. smallint(a) Ths onal wah can be added in brackets to the integer " a . lave any effect on t i 4 cigs wl also be stored as the waa sone on ibe value stored. Integers with more than The fol il lowing table illustrates the fractional data types and their storage requirements. e range of o The ra 8¢ of values has been omitted as they are very large and are expressed in scientific 3. 37, 20, 36, 85, 47, 75, 808 to 92, 23, 37, 20, 36, 85, | 8 bytes unsigned the range of values the column can contain is 0 to Type Storage FLOAT(,s) bytes DOUBLE®S) | Bbytes DECIMAL(p,s) 4 bytes for every nine digits p> Precision : The total number of allowable digits both before and after the decimal. The default value of precision is 10. s—> Scale : Total number of allowable digits after the decimal point. The default value of scale is 0. * The float and double data types are used to represent approximate numeric data values. The decimal data type is used to store exact numeric data values. This data type is used to store values for which it is important to preserve exact precision, for example with monetary data. e.g. DECIMAL(6,2) means 4 integers and 2 decimals. DECIMAL(8,3) means 5 integers and 3 decimals. BOOLEAN DATA(TRUE/FALSE) Boolean data are represented by the constants TRUE and FALSE which‘evaluate to 1 and ©, respectively. These constant names can be written in any letter case. TEMPORAL DATA TYPES - The following table contains the temporal data They represent the date and time. in Type Format Values Storage | YYYY.MM-DD *1000-01-01' to 9999-12-31" 3 bytes | 1901 to 2155, and 0000 1byte om ma *- 38:59:59" 10 '838:59:57 3 bytes sand Applications (Fy. Pama wer or or “DD T7900 -01-01 00:00:00 0 " Parents [Oss «9999-12-31 23:59:57 |. {— —~_* j | 4p, information as the DATETIME cq,~ IME colin TIMESTAMP column bas the same Pn recente he dare and tie OF a SERT or UPDATE operation automaticay the first ‘AMP column that isthere in © table is set to the date and time 8 arent operation. if you do PO assign ita value yoursell eon STARTING MYSQL Download the MySQL softwat “You can download either versi cinder windows and complete the co igre a password. Remember this passwo} on start and select MySQL command line client ye from the website hetpy/ ion 5.0 or 5.1. Then install the MY figuration. During this ine ley, rd, as it will be required whet, en ye Yo, computer ask you to the software. To begin using MySQL, click ver Type the password and press. +~ asshown below. irane the FORGL non ond with 5 er Na. see eis Somme 1 reredsn! Eoict-retokmanity ML Camm ity terver my me ‘telsi' or *N for daly. 1; te clear the haffar, r for balp. Type "et Her. Abematively at the DOS cs en S prompt type the following : fou will be prom ipted to give the nw Password, type it and ready to an using MySQL. MySQL and i ratte anne its prompt as shown above.! 1. Asindic withasorig 2 ie below the pass = rd, each command yo u give should: 2 The ten gee You RA ia wppercage go oe MYSQL are not ase sensitive and hence you cant Petite payer ed ROt be giver nem ing tes are po al by resting 2 Dot on a single i Presting enter, ten Problem, rd line, -so lengthy Show a promo” Continue a y commands | Pt->, on the z Cominane into ine ere! Introduction to MySQL rrr ot i} can continue typing h the 5 4 onds by looking for the ionminer MySOl. determines where your statement " want to Y . promp. it from the MySOL type quit or exit at the MySQL command 5. There are a n ; 1 viewed simply baer Of administrative commands. These commands can be The following table rene he. W oF ? atthe command ine: ows each of the prompts you may sce and summarizes what they mean about the state that MySOL fj SOL is in [Prompt Meaning fnysal> [Ready for new commana alti 5 [we ing for next line of multipledine command. Jquote (*'*), Waiting for next fi I. xt ; 5 > *), line, waiting for completion of a string that began with a single . |Waiting for next ti > reste for Rex ine, wa ing for completion of a string that began with a double lWaiting for nex line, wan acktick <5" He. Waiting for completion of an identifier that began with a Waiting fc 7; 6 for next line, waiting for completion of a comment that began with /*. QUIT/EXIT command This is used to exit from the MySQL sofiware. Hence when you want to come out of MySQL software this command is used. Rype What is the difference between CHAR and VARCHAR data types? Explain Boolean data type. How are dates entered in the DATE data type? ‘What is the difference between DATETIME and TIMESTAMP temporal data types? IBJECTIVE QUESTIONS, State which of the following statements is True or False: Atable contains one or more databases. A database contains one or more tables. — char[10] will use 10 bytes of memory even if the data stored in it is containing aossiate 2) means there are 9 integer and 2 decimal positions. Boolean data type is represented by the constants true or false. Temporal data types are either integer or real values. is not a freeware. 3 woe stored in MySQL in the format dd-mm-yy¥y- | renting Databases and Tables MELEE Module - 94 SHOW DATABASES To work in MySQL tone you ng names of the existing databases s+ Nast @ database, SHOW DATABASES wil dipay the nysal? show databases; Database i 1 test 1 3 rows in set (@.08 sec> { information schena MySQL displays three exist took to show the result, g database names. At the end it also displays the time it CREATING A DATABASE For creating a new database use the CREATE DATABASE command. Syntax CREATE DATABASE filename. For example, to create a new database file called emp, use sq1> create database emp; eI ofr drow affected show databases? ' 1 Database ! 1 information_schena | | yea ' | test 5 een created and its name appears in the first in the list. Once a ith the same name emp it ‘Ajrows jin set (8.08 sec? rabase ‘emp’ has b ‘As can be seen, the ‘ ‘which is always a after information Sno nother database wi order [atabase emp is created ifyou TY and create an \palligive an error Da a . i ie oe a a database ‘en’ aves): can’e create een “ Compute Systems and Aricatons yy ww ram O. Write statement to create the database star. mysql> create database star; Write statement to create the database mango. mysql> create database mango; Q. Write statement to create the database atlas. mysql> create database atlas; Q. Write statement to create the database pune. mysql> create database pune; a. rder. ‘SE statement reeds Sttement will select and open the database you want Merete atabase, no table can be created or used. To selec Wonk with earlier, the command is ° select the daha rql> use emp; “ee Tihtes changed ‘ Alll the databases names except the first one, have been displayed j, mn alpha be, Select the database mango mysql> use mango; or mysql> use mango (The comma a mi is 1a at the end is o) mysql> use pune; Select the database ‘Star mysql> use star; >P DATABASE ‘statement This statement is used to delete the Ptional in USE statemen) of deleted, US Proceed : 'O make a table in this daabo® Creating Databases and Tables te el Unsigned means th, amiven immedistnns tb the Values in tha thy column it wie © data ype. Eg. eno smallint unsigned, ns Cause Shou be Not Null means that th; . e neraun column value cannot be empty. Default statement is used to Bive a colu , eg. SALARY DECIMA imn a fixed value, if no value is assigned to it. AUTOINCREMEN 72 UNSIGNED DEFAULT 1000 The AUTO_ INCREMI od : _ z ENT modifier automatically generate a namiter iS used to indicate that MySQL should can only be used with int that column as the value of the previous row+1. It column ina table. ‘eget data types. There can be only one AUTO_INCREMENT e.g. PR_ID SMALLINT UNSIGNED \UTO_INCREMEN ID Ne OT NULL Al A Primary Key is one or more columns in a table that uniquely identi the table. For most tables you create a Pri 7 iquely identify each row in TABLE statement, you need to add the Prima) key douse aerihe cota ‘Getaiion. og EMPID SMALLINT UNSIGNED NOT NULL PRIMARY KEY or add a separate constraint at the end of the CREATE TABLE statement as follows : CONSTRAINT PK PRIMARY KEY (EMPID) A table can have only one Primary Key. FOREIGN KEY A Foreign Key is a column in, one table which is identified as the Primary Key in another table. A Foreign Key establishes a relationship, or constraint, between two tables. A Foreign Key maintains the consistency of the data between the two tables. You can define a Foreign Key in the column definition or as a separate constraint by adding a REFERENCE definition. FOREIGN KEY (empid) REFERENCES epay (empid) . Here empid is the Primary Key in the EPAY table, and itis defined as the Foreign Key in the current table. : SHOW TABLES This command is used to view database. Q. To view the names of the tables in _— the names of the tables that are stored in # the database emp (elect the database emp) myaql> show tables; <———. (To display names of tables) Fs Empty set @.00sec) . OR = stems ona hppicaons T7 m Empty se me ted in the aatabase © p, the Empty 94 rn eal “6 ‘as there are no tables cr displayed. followed by SEATING ATABLE . caeATE TABLE sete their data ve tat To create arable We UE urns the tal and then write name characteristics. with the columns Q. Create a table pay in the data] 7 ia res aracterisi TCotamas | inte On icin of [employeename 4 RAMS [meget rath of a ae age revacter wih variable width of ow ae “aith 5 integer and 2 decimal pl salary e date of birth dob oe i ‘The command is : > use onpé Buddhare changed 1) create table pay pore Elapid snaliine prinary key 3 nano warehar 26>, 5 age analline efey onrchar(2e>.. Salary dgcinal(7:2)- dob date); Puery OX, 8 rows affected (8.06 sec? To verify that the table is created, use the command SHOW TABLES as folloy;, nyse)? show tables; TTabiee_ain_omp | iw i row in eet (8.68 sec) ‘Observe that the name of the table pay is thown in the database emp. Now let i \ soe et ts crete a new table called DEPT in the database ATLAS with the smallint unsigned varchar(20) smallint varchar(20) smallint [ae date using the create table state Creannn Matabases and Tatty To verify th: . Example : Write a information of the “sou state , Integer. Prim: columns, should nee wo >. Employee New default value as “M") and ga): der (GENDER Cee late Character, Solution: CREATE TABLE onan (OJ, Date), Note : The solutio 1 can Be written in lower case also, as MySQL is not cese ser Example + Write -a MySQL following columns, em number GHSING eng ee ee incremented by 1 automatically), hem eNO: Unique postive integers 15 columns, should not be empty), name (INAME, character, having vez: market price(PRICE, width 10 which poe ne SOCKOPSTK, INTEGER defa sale (DOS, Date). incudes 2 decimals and a decimal po’ Solution: CREATE TABLE INVENT oe SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY ¥ [AME VARCHAR(15) NOT NULL, OPSTK SMALLINT DEFAULT 0, PRICE DECIMAL(.2), DOS DATE); Note: 1. In auto_increment and primary key clauses any one can be writen Sx. 2. _ Unsigned must appear after the data type. E.g, smallint unsigned Example : Write statements in MySQL to create a database called TRUST and it. Then create a table called DONATION containing columns Donor identity Donor’s name(DNAME Character, width 20), Amo (DNO, Integer, primary key), ‘Donated (DAMT, Integer), Date of donation(DT, date) which should not ‘be empty. Solution: CREATE DATABASE TRUST; USE TRUST; . CREATE TABLE DONATION (DNO SMALLINT PRIMARY KEY, DNAME CHAR(20). DAMT SMALLINT, DT DATE NOT NULL); TABLE USING DESC : LUMNS FROM PAY will dis) Pay or SHOW CO! in names, their data tyPes ice. it i. STRUCTURE OF THE of the table pay will display the columt vegas rd MODE TY. Dy B a emp in which this table js ¢) ing the datal Pay rust use tH peesetenanee There! pane —t pafeaie | Bare! os > degersbe Pay! (pow in sot (0.01 vec? . Took at the code used for ereating a table PAY, we use statement mysql> show create table pay: ; Fevew the structure ofthe table DEPT in the database ATLAS jeql> use atlag? Hiedbace’ changed Bacabace hyoet? dene dent . trict | Type Twili | Ney | Default | Extra f. ieee ne id of Lint (5) uns ed 1 MO of PRE! MULL 1 1 mid, { sraddinesss metered tes dT MULL 1 ptid | smallint(6> 1 YES. I 1 MULL t t | eity © | sarehar(Z8) ives 1 1 MULL Of : [i mgrid | smallint¢6> TYE f 1 MULL t 1 [t galary | decinat¢7.2> 1ys 1 1 MULL Ot i I date ives tt MULL Ot i hao, Pf rove in set (0.09 sec) INSERTING DATA IN THE ROWS OF THE TABLE (INSERT INTO) The data entered in a table is in the fc form of rows of di ‘Statement in th frumex cas eae nan, he clunn names and te data beng Neen este is inserted in the table pay : mite Mtatase changed weil) insert into pay « valnanane ace ity, salar > tinaz’ ,. ‘punba: ery OK. 1 row atfected’ (Oras ant However col lumn Columns in the table, b> 45088, 11979-a5-19» y; | ting Databases and Tables on reo Now let us enter ano emered. ther row to the table with data for city and dob not being a1? ingore int nvea"S Compid.nane-nee-s. ae Ritter watt ary? query OK. 1 row affected 28 aa ceed, nysal? select * from pa 4 1 30° Tr 1 | 8 nunbas 1 1 1979-86-17 | 1 1993-89-28 1 '@B | 1984-83-02 | 1 MULL ' 14 maral it 38 frows in set (8.08 sec> Notice that the columns cit entered for these columns. ity and dob are showing NULL for empid 4 as data was not The query to view only the empid, name and salary columns from the table pay is : nysql) select enpid,nane,salary > fron pays — fenpid Pname t salary { ——+ 1 i} pinaz | 45000.08 1 ! 2 | sharukh | 20000-68 | 1 ZU riyaz | $0088.60 1 4thiral | 33008.60 i ———+ —- 4 rows (rows dn set (0.68 sec) Let us use the INSERT INTO statement to put data in the table DEPT which is in the database ATLAS as follows : 11> use atlas; Patabase changed 45008, 1990-83-85"), See etban,'199-42-@F">. S18 ,298@8, 208269 88" S11. 48088,’ 1995-23-82 ' ee 508 "i-th, | Bahtrows of data have been added to the table DEPT. view the of data inte ble der. we use Computer Systems and Applications (T.y, B.Com) Sen, rr 0 f the table. ¢, UPDATE and SET nents make changes in a he Bie can be “rails These statements are used 108 The data contain * tal . table PAY from the dai writing the query mysql> use emp; Database changed — lect * From pay; — 1 weal? spec wieity i eatery | dob + enpid | name I age fc 1979-96-47 | 1 i pine | 301 eambal 1 1993-99-28 | 2 1 Gharakh i 3g y gune, | 2008 Agea-e3-e2 | athe | 6 | MULL =| 35e08.88 | 2 +78} rows in eet <@.68 socd | in the The UPDATE and SET statements are used to modify the feta in the rows of table. To change the age of Employee [d 4 (hiral to 29 the c veql> update Pay > 2! poset snvideas et roa ious matcheaTy Chang lect = from pays + rom pays enpid | name lage | city} salary | dob ! 11 pinaz ! 3e1 mumbai { 4Se08.e8 | 1879-@6-17 ' 20 hare] I = Aika | 2 Bah jae | RES | ka t * E088 aggy eee | Ha | Fows in set 8.88 fec> Notice that the age of ‘hiral’ has changed from 28 to 29. Using UPDATE statement we can also give y, ity an ‘ol i P eve values to the city oon’ id dob c, lumns fe wearing Data id Tables rer ” yea) updntn y 2} apt averegest salary aadaryes ‘OK, 1 row affected (A.83 a wrath Sheed P83, 00) mart t 1 dob 1 j nas {aah __t 2 1 sharukh | 1 1879-86-14 it A7 1 31 rdyaz 1 1 1993-87-28 | ! It 41 hiral 1 1 1984-#3-82 | 1 1998-85-82 1 ‘Y CREATING A TABLE USING ANOTHER TABLE ‘A table can be ci containing the ‘columns ony using the columns and data from another table. A table PAYI corto: pid, name, city and salary can be created using the table PAY pysal? create table payt elect id, fron Daa : nane-city.salary ery OK, 8 rove affected (a, queryac?'O. Duplicates! 8 Wareinee> @ ins and confirm the creation of the table PAY1 we use the SELECT statement as > lect * veal} podeet a renpid i name | city | salary 1 I 41 pinaz 1 mumbai_ 1 f 2 | sharukh | pune | Zooea:oe | | 3 [ rigaz I delhi | 5egaa.aa 1 i 6 4 t hiral 1 NULL {| 3S000-00 1 + _—--=-+— rows in set (8.03 sec> The above table PAY! contains all the rows of the table PAY for the selected columns. However, it is possible to give a condition and select only required rows while creating a new table as follows. nysql> create table pay2 eS select empid-name,city,salary -> from pa: % => where city = ‘mumbai’; Query OK, 1 row affected (8.10 sec> Duplic: @ ‘Recorde= 1 Varnings: @ ‘0 view and confirm the creation of the table PAY2 we Hollows ios use the SELECT statement as —-———+ P ' I-salary | plications (Ty. commer St oe nb city ‘mune Iy the rows from UMbaj: by oor ° Ie displayed above contains ont able d odify and delete columns Le. ty y ate P: jo rename the table, ER TABLE statement, id, me a TABLE statement Is used (0 ad, ee anges in the structure of the table. ch table PAY, a new column bonus, Wh with default value 099" ADDING . ld to the COLUMN {ADD). To ad Ne) be eee value cannot be negath ) 4 integer and 2 decimal places the comma 1¢6,2) unsigned default 1880; ted ayeq]> alter table pay fected describe pays . —+——______. + t Field t Type I Null | Key | Default ! Extra ! Eten Tipe smal: 1 NO | PRI oT MULL I t jsmie} pinece? VES NULL t a 1 emallinec6> Ives 1 | NULL I I | eke | sineresss Me | jie ft t & {SRO | BSc wines 1S iNet | cima: a unsigne: jel ! 2 Bonus ? rows in set (8.08 sec) een added as the last. column in the table. The bonus column has b value of 1000, which means if no data is entered in this column it will a the value 1000. To add bonus column after the age column the command is nesgl> alter table pay 5 optd bonus decinal¢s.2> grsisned defaule 1899 a aft 3 Ronee” RpLamecresg Gcitaey™ mans To eda bonus column asthe frst column in the table the command is "vsql> alter table y opt bonus detigarce 2 unsisned default 1888 First: Query ox, @ rous aff; Bs Re Puplscateer @ Wals,0e? 9 creating Databases and Tables CHANGING COLUMN NAME (CHANGE) CHANGE statement is used column in a table. To chan, command for this is : along with ALTER statement to change the name of a the name of the column bonus to e_bonus, the nyeql? alter table pa e Pearce" ales east? 2) unsigned default 18508; @ Duplicates: @ Warnings: @ nysql? desc pays w+. . + IT. | Field ‘ype t Mull 1 Key ! Default i Extra i Tompid . | snalline <6? Yeo 1 PRET MULL 1 T name 1 varchar¢28: 1¥ES ft 1 NULL t 1 tag 1 varitineces 1¥ES ¢ 1 NULL 1 t I city 1 varchar¢28> 1 YES 1 1 MULL t 1 Hgatary | decinal¢7.2) 1yes $0 {MULL I 1 dob I date Ves f of MULL 1 | shonus 1 decinal¢?,2> uncigned | YES |__| 18588.08 | ! = + + + + ? ro rows in set (8.88 sec? Notice that the column name has changed from bonus to e_bonus. DELETING A COLUMN (DROP) To @elete the column e_bonus from the table PAY the command Computer Syeters ened APPEATIONS TY. 1, computer § ” wr 1 KEY. DELETING/ADDING THE PRIMA ein the tal pe used 10 remove le PAY the primary ke Is empid ag gps } her table can b ada a nnmary key to te table. For the weal? deve payt To remove or delete the primary key from the table PAY the command is : nycal> alter table pay > dro prinary, ke Query OK, B rows, aff Records: @ Duplicat To verify that in the table PAY the (8.16 sec) +8 Varnings: 6 primary key has been deleted we giv, a command . ee a LFiold 1! Type J Mull | Key | Default | Extra { on om ng neg nnn g extra | wid J omallintc6> 1 WO ft MULL 1 met varchar¢28) | YES MULL y 1 1 {MLL ft t 1 MULE 1 1 IML y 1 t My e YEE do ' rows in sot (8.81 eocd * Notice that the indi i Not le indication for primary key for empid has been Temoved in the ke i] To verify this we Give the command - ee ee + —— tMualn 7 Koy 1 Default | Extra oe + t oe + 1 i ! 1 t + | eee and Feber puss? show tablea; incenp i 8.88 ey We can also rename a table the rename statement as follows directly ‘without using the ALTER statement, by only using DELETING A ROW(ELETE statement) To delete a row we us delete all te rane © the DELETE statement. Ifthe WHERE clause is omitted, it will To delete the row of ‘hiral’ th is 21>? delete Fron lila In => where empid= ery OK. 1 row aff, Pinas | sharukh Notice that there are only 3 rows left in the table. The row containing the name ‘hiral’” is deleted. DELETING ALL THE ROWS(DELETE statement) nysql> delete fron epay; Query OX, @ rows affected (8.08 sec) As where clause is not used to indicate which rows should be deleted, all the rows of the table EPAY will be deleted,. There will be no data left in the table. DELETING A TABLE(DROP TABLE) To delete a table, use the DROP TABLE command followed by the name of the table. To delete the table epay the command will be: mysql> drop table epay; Query OK, 0 rows affected (0.05 sec) The table epay will be deleted, i.e. both the data and the structure of the table are 1R What ts the difference between DROP and DELETE? a i Je or any column in the table. e.g. drop table er is used either. to delete the tab! ‘DELETE is used to delete a row or rows of data in the table. e.g. delete from pay: é mns Employee name (ENAME init salut be addres (ADDR. Character), Gender (GEN (GONE. meee sed Salary (SAL, 5 integer and 2 decimals). “ CY. BG . fications (TY. B.Com y 4 »- rer systems ond Apa Say Commuters in: the follow! r jals to the table, for 1 statements te. lecim write MysOb snare of the ra nq 5 integer and 2 1). Display the sr BONUS having column ca BON. i) ‘Adda «the colurin BONUS a5 tary for all employees: Fen ie cponus as 10% of the Sal iv) Calculate t v) Delete the table EMP. Solution 1, DESC EMP; 2. ALTER TABLE EMP [ADD BONUS DECIMAL (7.2); 3. ALTER TABLE EMP ; CHANGE BONUS BON DECIMAL (7.2); 4, UPDATE EMP SET BON = SALY.10; $. DROP TABLE EMP; Write statements in MySQL for the following : Display the names of all the databases. To create a database dept. To select the database dept. To see the list of tables in the current database, To see the list of tables in the database dept. Write a MySQL statement to create a table named BILL containing it i tal 1g informati. customers staying in a hotel. The table must have column for customer's mane (CNAME, character, variable of width 20, distinct, not empty), customer’ addres (ROOM, integer), type of room (CADDR, character, fixed width 50), room number (TYPE, character, width 10, not empty, which contains default entry as “NON AC’) and days stayed (DAYS, integer, Positive), 7. Write a MySQL statement to create a table named ECHARGE L L 2 3. 4 5. 6. company, having the columns Customer's ide, cs e er's identification number (C_ID, distis 220, Customer name (CNAME, character, variable width 20, UP sine | creatine Derabraces and Tate 9, Write MySOL statement, vee table LIBRARY using ‘am create a database COLLEGE - —e f — ” ce create a [Number of pages 10. Write a MySQL statem ———_1 eer hed sree a to create a database PAY. In this database create a table key). item name NAME, following columns, Item number (INO, integer, Primary SOCK(OPSTE, tntope eee character, having variable width of 15 columns) opening negative), closing stock(CLSn r value 0), Purchases(PURC. integer, should not be date of sale (DOS, Dan gcLSTE: integen, price (PRICE, width 9 with 2 decimals) and .b) Writea My the employecs oni nement © create a table named DEPT containing information of integer primary key), Emplo ing columns, Employee Identification Number (EID. columns), Basic Salary GSAL wi Name (NAME, character, variable width of 15 negative). DA (DA wih s ten 5 integer and 2 decimal places should not be and 2 decimal places) Toate and 2 decimal places), HRA (HRA with 4 integer not be negative) and dete tty CTSAL with 6 integer and 2 decimal places should To ctoate e table wy irth (DOB, date). a owe ‘ca le with name BIKE, containing the columns Bike identification number eracien wanlste mary key, incremented automatically), Name of the bike(bikename, eT nei Ith 30 characters and cannot be empty), cost of the bike(bikecost, als), and the date of purchase of the bike(pr_dt, date). 13. Create a table called STUDENT containing columns to store Admission no.(admno integer, primary key), First name (fname, character variable width of 20 cols), Surname(sname, character yariable width of 20 cols), and Fathers name(mname, character variable width of 20 cols), gender (character width 1 col), date of birth(dob date), date of admission(doa date), class admitted to(class variable width. of 10 cols), fees paid(fees with 4 integer and 2 decimals). 14. Create a table called LIBRARY containing columns to store Student Identification no.(stud_id, integer), accession no.(access_no character variable width of 10 cols), book name(bookname, character variable width of 25 cols), author's name(authorname, character variable width of 25 cols), date of issue(doi date), date aeetuen(dor date) where student Id should be the foreign Key to the table STUDENT linked by admission no. 15. Create the table DEPT containing the columns id(id, smallint), name(name, varchar(20) ) where id will be the primary key. Create a table EMP containing the columns i a vaschsr(75), fist name(frst_name varchar(25)) where dept_id will be the foreign key to the table DEPT. a) ee a Jun last_name to varchar(50). id (id, smallint), last name(last_name, department id (dept_id. smallint) lg EMP change the col nent to create a tal ible called CONSUMER having the columns FCNO, distinct integer). Consumer Name(CNAME, character with not be empty), Type of Connection( ‘ Coen rss with default entry ‘Industrial’) and Units N i umns Account ie called BANK having the columr unt itor Name( DNAME, character with varial distinct), Depositor and Applications TY. B.Com, Bf ner Ste eposited( DEP, 6 in. Be, Deposit having the columns | rable called TART aracter with variate, come Tax ( ITAX, ve a , Ine rege) Date). i 19, Wri a ary key). N arge in! umbert INO. Ine rec ING, very eg ipmission( DOS. Columns), Taxable Incr and Date fhe columns department j integer, should not DE MENTS containing the tyme, vatchar(25) sh Ides, Create the table DEPAR department ee or ccation_id intepen'" 2! 20. eae te pty). name i “nteget). focation id(ocation_id integer), ee ager! ), manager id(mané sree primary seh a) Display the structure of this table. b) Add 8 rows: ‘of data to this hae led BIKE contains the 2 Aa incremented autora veable width 30 characters and cannot De erm Wan’? decimals), and the date of purchase of tl statements for the following : '). To show the structure of the table bike. ji) To change the name of the column bikename to bkname. To change the size for the colurmn bikecost from decimal(6,2) to decimal(g 2) iv) To add a column sale date(sl_dt) to the table. How will you indicate that & mns Bike identification number (bikeig veal), Name of the bike(bikename, ¢hr't ty), cost of the bike(bikecos, he bike(Dr_dt, date). Wri yt should be the first column in the table. v) Todelete the column sale date(st_dt) vi) To insert a row of data in the BIKE table-giving the bikeid i asl, bikename » Honda, bike cost as 75,000 and purchase date as '2009-09-21". vif To change for table BIKE the contents of the column bikecost to 80. ,000 fy, yen bikeid 1. vill) To delete the row from the table BIKE whi il ere the bi is" ' ix) To delete all the rows from the table BIKE, Menames Honda %) To rename the table BIKE to MBIKE, x) To delete the table MBIKE. 22. Atable SALARY contains the Neme(ENAME, sets the columns employee number(ENO, int it i ‘n MySQL statements for the following ; , “ i StU of the table SALARY. Delete the row where emp) , loyee num! is R the cotimn DOB io beg ber is 101, i 3 decimals, decimals to this table. 13 to "Manoj Pai', ining th : chen amns student name (SNAME, cron, width 10), division (DIV, --LEC, numeric integer). ROLL, i ‘nteger) as first column the table. Creating Databases and Tables, oor n 25. a» ii) Display the structure cluire of, iii) Rename the column sua iv) Increase the number 10 NAME, : of lect W) Delete all he oun wna ects attended by al he students by 1. wi Delete the column DIV from qe go PBC vi Rename the table ng “ATID nae table. REPORT’. , There exists a table TC] ‘LASS with columns for roll number(RNO, integer), name of the student (SNAME g haracte width 10) and marks obec variable wii 20), subject offered (OPT character, KS) teger). 2 mn mr low i) Update the subj fore, Ject offered as COMPUTER when marks obtained in SY is 60 or iii) Change the name of the cotum iv) Inc i OPT to OPTS. » Change the a Obtained in SY by safer a the students, Sub lect offered by roll number 123 to ‘COMPUTER’. vi) Add a new column divis di column. vision (DIVI character width 1) to this table after the name vil) Delete the table TYCLAss, There exists a table No (REGNO character), Model of 8S having the columns Registration Number date), and value of the car (VALUE, one character), Date of Purchase (DOP, ‘Write MySQL statements for the folowing. i) Display the structure of the table. i) Add this \ , a a sow of data ‘MH O1 A 2053’, HONDA','2013-10-23',1000000 to this table. iy ha MAKE of car having Registration No. MH 02 XJ 1230 to ‘Maruti’. 2 aa a new column Date of Sale(DOS, date) to this table. v) ete all the roy i u Dees ws from this table where the date of purchase is before June 15, vi) Rename the table NCARS to CARS, vii) Delete the table NCARS, a State which of the following statements are True or False : USE PAY; will select the table PAY. USE PAY; will select the database PAY. The DEFAULT clause is used to give a column a fixed value. AUTO_INCREMENT clause is used to indicate that the value of that column should automatically be one more than the previous row, show emp; will display the structure of the table emp. desc emp; will display the structure of the table emp. Atable can be created from another table. ‘Alter statement is used to make changes in the structure of the table. Once a column in the table is called a primary key then it cannot be changed. Only one row of data can be entered ina tableatatime. = - . reations (TY. B.C Applicators Cm eg tumns need not he on Compurer Systems and mes of the Col © , ing dal n , ile enterin as is being entered a. pms is . data of allthe colin data in the table update and se! 12. To make changes can be Ut 13, Once data is entered in a table it 12,3,4,6.7.8:1112 IL. ‘Select the appropriate option from the following + "To select a database TAX the statement is__- oS (b) Choose Tax 1 (@) Select Tax .U88 Tax (©) Open Tax 2. To view the structure of the table DEPT the statementis___- (@) Desc Dept ) Decs Dept (© Dept Desc (@ Show Dept 3. To make changes in the data already entered in the table we use — (a) Alter Table (b) Update and Set © Select (d) Create . 4. To view the names of the databases in MySQL we use @) Show Tables (b) View Databases (©) Show Database (d@) Show Databases 5. To indicate that the values in a column are positive we use @ Null (©) Signed rina elps to uniquely identify each row ofthe table is called key. (©) Foreign (© Secondary @ Main 7. In the ALTER TABI cause ILE statement to change the name of the column we use @) Modify (©) Add @ oe Be 8. delete from pay; statem 5 ro ‘ lent will de (@ ALL Siete __ the rows from the table Pay. (© LAST 10 © @ PRsT s . (@) FIRST 10 hone. ANSWERS a-d,@ BP, 6-0, 6-0), 0-0), @- roe ‘Built in Functions in MySou, Inbuilt functions in My pave been categorized Megat Feadymade functions which can be used directly. They ing functions, Date(Temporal) functions and Numeric functions. STRING FUNCTIONS ——TLOWERGt) or loa SSS 1. LOWER(str) or LCASE(etr) Returns the string str with all alphabets in it converted to lower case. mysql> SELECT LOWER(: . UPPER(str) or On Seater Returns the string str wit init mystl> SELECT UPPERC shanna gro 3, REVERSE(str) Retums the characters in the string in reverse order. mysql> SELECT REVERSE(‘surat’); gives tarus mysql> SELECT REVERSE(‘Liril’); Gives liriL 4. LENGTH(str) Returns the length of the string str. It counts all characters including blanks. mysql> SELECT LENGTH(‘Hello There’); gives 11 5. LTRIM(str) Returns the string str with leading spaces removed. mysql> SELECT LTRIM(‘bBFG’); gives FG \ RTRIM(str) Retums the string str with trailing spaces removed. _ mysql> SELECT RTRIM(‘FGbb’); gives FG Une(et : ; trailing spaces removed. ms the. string str. with both leading and > SELBCT TRIM(bOFeGbb ): wi the leftmost len characters fro oe smed. > ae gives FbG m the string str. If len is zero or negative an gives MAN mputer Systems and Applications (Ty. ¢, Cor Me, » one . 1s from the string st. If len iS zero op ms jaractel Ch 9. RIGHT(str,len) len ch the rightmost len Returns the right gives JULA sing is returned. vas srysel> SELECT RIGHTCMANIUA ‘ay posen) pameninnone aE starting with the position pos from the . i nis on ae Of characters starting an the position pos are Obtaineg r is omitted, acter . zero or negative an empty sting is renume giresdU mysql> SELECT MIDCMANJULA‘42); || GES meal SELECT SUBSTRING(MANJULA'A); gives 11, CONCAT(str1,str2,...) ; , Returns a string that is obtained from joining all the arguments in the fun, twill return NULL if any of the arguments are NULL. a gives MANJULA mysql> SELECT CONCAT(‘MAN','JU’,'LA‘); i mysql> SELECT CONCAT(‘MAN',NULL, LA’); gives NULL ction, DATE FUNCTIONS 1. NOWO Retums the current system date and time as a value in "YYYY-MM-DD HH,yy. YYYYMMDDHHMMSS format depending on whether this function is used or numeric format. a mysql> SELECT NOWO; Gives 2009-11-01 16:19-47 mysdl> SELECT NOW0+0; gives 20091 101161947 2, TIME(expr) Extracis the time from the datetime expr mysql> SELECT TIME('2009.11-91 16:19:47'): gi 3. Daren 6:19:47); gives 16:19:47 ‘Built in Functions in MySQL. re ir 9. MONTHNAME(date) Returns the name of the month for the date, mysql> SELECT MONTHNAME('2009.1 1-01); NUMERIC FUNCTIONS 1, ABS() Returns the absolute val ithout its si bi ens ue of nie, value without its sign, mysql> SELECT ABS(3); 2, POW(,y) Returns the value of x” mysql> SELECT POW(2,3); gives MOD(x,y) Returns the remainder of the division of x by y. The answer will take the sign of x. mysql> SELECT MOD(10,3); gives 1 mysql> SELECT MOD(-10,3); gives -1 mysql> SELECT MOD(3,-10); gives 3 4. ROUND(n,d) Retums the number n rounded to d decimals. If d is omitted or 0 it returns nearest integer. If d is -1 then it rounds n to the nearest 10. 83 gives November Bives 3 3. mysql> SELECT ROUND(2.67); gives3 mysql> SELECT ROUND(12.328,2); gives 12.33 mysql> SELECT ROUND(77,-1); gives 80 + 5. SQRT(x) Retums the positive square root of x. gives 7 gives NULL Here are some examples using the built in functions listed above. Example 1. To display the remainder of 10 divided by 3, the square root of 12, absolute value of -5 and 2 raised to the power of 5. * ql> select pod(18,3>, sqrt (12>, abs (-5>,pows2.5?;, . |! mod(1@,3> | sqrt 1 abs¢-5? | pow(2.5? t 1 1 3,4641816151378 | st 32 ! |.83 sec? “2. To display the value of 37.274 rounded to 2 decimals.1 decimal, integer, (pnearest 10. ‘ , .4¢37.274,8>,round(3?.274,-195 f 274,49 round 7 274,89, round 37.274, Vahegeqh> select round(37.274.2),round<37, Danian rt 1974.4) | round(3?.274.! Sweund<37.274,2> | reund(37. att et a = set (8.08 $576 show the system time and date. 1 ¢ i > Computer Systems and Applications (Tp ¢, oer os it je japter. Consider the table EPAY used in the previous chapt ogi? select » Fron opay mata Tage | city pity _.. 1 1979-B6-17 | inbad | $0008 88 | 1393-89-28 1 3a few 8 | 33 ee | T pines, ! {2 F pines, 20908 -68 Sharakh | 46 1 Jee | 198: [State Tt 35 Heth | Soo-08_ 3 t wiyaz rows in set (@.08 sec? Example 4. To obtain the dayname and day.month.year for the date of yj. employee id 1 using separate commands. 1} golect dagnane dab? 23 Fran 23 where Enpideas I daynane i dayCdob), nonthdob>, year dob) => From epay => whore enpidet; | dayCdob> | monthCdob> 1. yearCdob> i él 1979 i row in set (0.81 seed Example §. To display the name of Employee ID 1 in ‘uppercase and the first and lag; alphabets of the city, ‘ Ul} select upper(nane), left Ccity,1).rightCoity,2> 3 vere esas <—____; | wpper Fron ~> where = row in set (8.88 sec) * to net losing ulin incon in gee 2 Be / ® oa (c) me (@ Daynamed @ Lengng in finction in MysoL . Ea 0 (2 Modo @ Abs wy ‘allowing buat in (@) Ltrimo ® a : ‘ mmm tet OMe sqaro 0 suit in Functions in MySQL. 4. weyppree on the following built in function in MySQL ° (&) CONCAI D (ce) LOWERO oO MONTHINAMED, pao 0 80. 0 Give the difference between a) MAXO and MINQ, the following : ©) DAYO and DAYNAMEQ 3 cane and Lowen ¢) LEFTO’and RIGHTO 1) NOWO and Give the name of th and CURD AT t) To find the length ca in Runesione you will use to do the following + » me see the sistem date and time. ¢) To obtain t i ivi d) To obtain the home ofthe ces ndarotthe nek e) To obtain the square root of rene cay of theweek ) To obtain the first two characters from a string g) To obtain the last character from a string. h) To round a number to the nearest 10. i) To remove the leading blank spaces from a string. 1) To obtain the value of 6 raised to 4. 1) Tofind the month from the date. State which of the following statements are True or False : TRIMO function removes all the blanks from the string. DAYNAMEO function gives the name of the weekday. MOD(x,y) returns the quotient of x divided by y. NOWO returns only the date in the format yyyy-mm-dd, 'ABSOO gives the square root of X. True :2 False : 13.4.5 . Select the option from the following = i join the words is : papcaare sete © CONCAT() @ JOIN (@) MERGE() (pb) MOVEQ) at function which i the square root of x 1s __— ASOD eo sorTo) © © ORO (@ POWOD 1 the remainder of x divided by ys —~ mene 2 r © ABSHY) (© SQRTRY) (@ EXPRY) a function used to convert upper case letters to lower case Is wx {UPPERO. ) WERO (©) MINO | @ s hmction nk convert lower case letters to UPPEr case is ZS wx0 a a ) LOWERO () MINO @ (4-b» (6-8)

You might also like