Contents Unit 1 Basics of MySQL 1 Unit 2 Data Types 24 Unit 3 Data Definition Language (DDL) 52 Unit 4 Data Manipulation Language (DML) 90 Unit 5 Advanced Data Manipulation Language 114 Unit 6 Subqueries 133 Unit 7 Operators and Functions 153 Unit 8 Advanced Functions 183 Unit 9 Transaction Management 214 Unit 10 Stored Procedures 229 Edition: Spring 2009 th BKID – B1003 10 June 2009 Unit 11 Control Statement 242 Unit 12 User Account Management 253 Unit 13 General Security Issues 281 Unit 14 Log Files 294 References 311 Prof. S. Kannan Director & Dean (in-charge) Directorate of Distance Education Sikkim Manipal University of Health, Medical & Technological Sciences (SMU DDE) Board of Studies Dr. U. B. Pavanaja (Chairman) Nirmal Kumar Nigam General Manager – Academics HOP – IT Manipal Universal Learning Pvt. Ltd. Sikkim Manipal University – DDE Bangalore. Manipal. Prof. Bhushan Patwardhan Dr. A. Kumaran Chief Academics Research Manager (Multilingual) Manipal Education Microsoft Research Labs India Bangalore. Bangalore. Dr. Harishchandra Hebbar Ravindranath P. S. Director Director (Quality) Manipal Centre for Info. Sciences, Yahoo India Bangalore Bangalore. Dr. N. V. Subba Reddy Dr. Ashok Kallarakkal HOD-CSE Vice President Manipal Institute of Technology, Manipal IBM India, Bangalore Dr. Ashok Hegde H. Hiriyannaiah Vice President Group Manager MindTree Consulting Ltd., Bangalore EDS Mphasis, Bangalore Dr. Ramprasad Varadachar Director, Computer Studies Dayanand Sagar College of Engg. Bangalore. Content Preparation Team Content Writing Content Editing Mr. Nirmal Kumar Nigam Mr. Vinayak G. Pai Assistant Professor, HoP – IT Assistant Professor, Dept. of IT Sikkim Manipal University – DDE Sikkim Manipal University – DDE Manipal. Manipal. Instructional Design Mr. Kulwinder Pal Senior Lecturer (Education) Sikkim Manipal University – DDE, Manipal Edition: Spring 2009 This book is a distance education module comprising a collection of learning material for our students. All rights reserved. No part of this work may be reproduced in any form by any means without permission in writing from Sikkim Manipal University of Health, Medical and Technological Sciences, Gangtok, Sikkim. Printed and published on behalf of Sikkim Manipal University of Health, Medical and Technological Sciences, Gangtok, Sikkim by Mr. Rajkumar Mascreen, GM, Manipal Universal Learning Pvt. Ltd., Manipal – 576 104. Printed at Manipal Press Limited, Manipal. SUBJECT INTRODUCTION
“RDBMS with MySQL” is a 4 – credit subject in third semester of BSc IT
program. MySQL, the most popular Open Source SQL database management system, is developed, distributed, and supported by MySQL AB. Open Source means that it is possible for anyone to use and modify the software. Anybody can download the MySQL software from the Internet and use it without paying anything. If you wish, you may study the source code and change it to suit your needs. The MySQL software uses the GPL (GNU General Public License), http://www.fsf.org/licenses/, to define what you may and may not do with the software in different situations. The MySQL Database Server is very fast, reliable, and easy to use. MySQL Server works in client/server or embedded systems. MySQL is named after co-founder Monty Widenius's daughter, My. In this book on MySQL, we would lay the emphasis on the applications of MySQL in solving the database related problems and also deal with the coverage of every aspect related to MySQL. The SLM of this subject is divided into 14 units, the overview of which is given below. Unit 1 Basics of MySQL: This unit introduces the user to the basic theoretical concepts and features behind MySQL. Unit 2 MySQL Data Types: This unit introduces the theoretical and practical aspects of dealing with various data types of MySQL database, their syntax, usage and applications in the real world. Unit 3 Data Definition Language (DDL): This unit starts with an introduction of Data Definition Language Statements used in MySQL. It describes the syntaxes of creating and modifying Databases, Indexes and Tables. Unit 4 Data Manipulation Language (DML): The Data Manipulation Language or DML statements are used to manipulate the data inside a database. This unit introduces various DML Statements built into MySQL. Unit 5 Advanced Data Manipulation Language: This unit deals with the advanced DML Statements which is an extension of unit 4. It deals with Join and Union operations used to join database objects like tables. It also deals with various other operations of truncating the data, Updating or Modifying the existing data. It speaks about the specific operator Do, Handler and Replace. Unit 6 Subqueries: This unit deals with subqueries. A subquery is a query written within a query where in the result processing is segregated among the inner and outer queries. Unit 7 Operators and Functions: This unit introduces the reader with all varieties of operators used in both SQL and also in case of Functions and procedures used along with them. Unit 8 Advanced Functions: This unit deals in detail with the next level of functions used in addition to the functions discussed in the previous unit. It discusses regarding the Full text search functions, Cast Functions Encryption Functions, and the usage of Group By clause with various functions, and modifiers. Unit 9 Transaction Management: A Transaction is a series of one or more SQL Statements that are logically related or a series of operations performed on table data. This unit introduces to the reader with various statements used in MySQL to treat with Transactions like Starting Transactions, making the output of the transaction permanent by using Commit Statements. Unit 10 Stored Procedures A stored procedure is a set of SQL commands that can be stored in the server. This unit discusses the commands used to create, alter, and Drop procedures and / or functions. Unit 11 Control Statements: This unit deals with various flow control constructs used in case of stored procedures or functions. Unit 12 User Account Management: This section describes how to set up accounts for clients of your MySQL server. The meaning of account names and passwords as used in MySQL and how that compares to names and passwords used by your operating system is discussed. Unit 13 General Security Issues: This unit describes some general security issues to be aware of and what you can do to make your MySQL installation more secure against attack or misuse. It also describes the methods to maintain security while transferring data into MySQL from external resources Unit 14 Log Files: This unit describes the importance of maintaining log files within MySQL. It describes various types of log files maintained in MySQL like Error, General Query, Binary, etc. Objectives of studying this subject After studying this subject, you should be able to: discuss the features and use MySQL for database applications define and use the appropriate data types in your applications Describe the syntaxes of DML Statements and use them appropriately Define and explain the syntaxes of DDL statements explain the usage of subqueries as applicable Describe the usage of various available operators and functions Discuss the concepts of Transaction Management describe the usage of Stored Procedures and functions in conjunction with flow control statements Explain the importance of User Account Management Define general security guidelines in the usage of database servers Describe the need of maintaining different types of log files The subject demands knowledge and understanding of the subject titled “Database Management Systems” bearing the subject code BT0066 of BSc IT First Semester with respect to both the theoretical and practical concepts.