This document provides an overview and tutorial on database concepts, SQL using MySQL. It aims to give the reader a lucid understanding of databases, relational database management systems (RDBMS), and SQL. The tutorial explains key concepts such as data normalization, data types, and the basic SQL commands of INSERT, DELETE, SELECT, and UPDATE. It also demonstrates creating a sample contacts database with multiple tables to illustrate storing and retrieving data using SQL queries.
Database management systems (DBMS) allow users to create and maintain databases. A database is a collection of organized information that can be easily accessed, managed, and updated. Relational database management systems (RDBMS) use tables to maintain data records and indices. The ACID properties ensure transaction integrity during database modifications. Normalization organizes data to minimize redundancy by dividing tables and defining relationships between them. Denormalization adds redundant data to improve read performance in read-intensive applications. Tables contain data organized into vertical columns and horizontal rows. Data types specify the type of data in columns. Primary keys uniquely identify each record while foreign keys reference other tables' primary keys to link data and maintain referential integrity.
This document outlines a 7-day training program for learning Oracle SQL. Each day covers different SQL topics, such as data types, DDL/DML/DCL commands, the SELECT statement, functions, joins, and more. An introduction explains what a database is and why SQL is needed. Descriptions of data types include CHAR, VARCHAR2, NUMBER, and DATE. Command types covered are DDL (for definitions), DML (for manipulations), and DCL (for control). The document provides an instructor and contact information, and concludes by stating the training will end after 7 days of content.
The document discusses various database concepts including:
1. DBMS, RDBMS, SQL, fields, records, tables, transactions, locks, normalization, primary keys, foreign keys, joins, views, stored procedures, triggers, and index types are discussed.
2. Key topics covered include the components and functions of a DBMS and RDBMS, the structure and purpose of SQL, database objects like tables and records, ensuring data integrity through transactions and locks, and optimizing database design through normalization.
3. Common operations on data like queries, inserts, updates, and deletes are explained along with advanced topics like views, stored procedures, triggers, and indexes.
A database management system (DBMS) is system software for creating and managing databases. The DBMS provides users and programmers with a systematic way to create, retrieve, update and manage data.
A DBMS makes it possible for end users to create, read, update and delete data in a database. The DBMS essentially serves as an interface between the database and end users or application programs, ensuring that data is consistently organized and remains easily accessible.Read more.........
- An object-relational database (ORD) or object-relational database management system (ORDBMS) supports objects, classes, and inheritance directly in the database schema and query language, while also retaining the relational model.
- An ORDBMS supports an extended form of SQL called SQL3 for handling abstract data types. It allows storage of complex data types like images and location data.
- Key advantages of ORDBMS include reuse and sharing of code through inheritance, increased productivity for developers and users, and more powerful query capabilities. Key challenges include complexity, immaturity of the technology, and increased costs.
This document provides an overview of SQL, including its objectives, history, data definition and manipulation languages, and basic concepts. It discusses SQL's purpose in creating database structures and performing tasks like inserts, updates, deletes, and queries. The document also covers SQL datatypes, keywords for queries, updates, and deletes, and both advantages and disadvantages of SQL.
Database management systems (DBMS) allow users to create and maintain databases. A database is a collection of organized information that can be easily accessed, managed, and updated. Relational database management systems (RDBMS) use tables to maintain data records and indices. The ACID properties ensure transaction integrity during database modifications. Normalization organizes data to minimize redundancy by dividing tables and defining relationships between them. Denormalization adds redundant data to improve read performance in read-intensive applications. Tables contain data organized into vertical columns and horizontal rows. Data types specify the type of data in columns. Primary keys uniquely identify each record while foreign keys reference other tables' primary keys to link data and maintain referential integrity.
This document outlines a 7-day training program for learning Oracle SQL. Each day covers different SQL topics, such as data types, DDL/DML/DCL commands, the SELECT statement, functions, joins, and more. An introduction explains what a database is and why SQL is needed. Descriptions of data types include CHAR, VARCHAR2, NUMBER, and DATE. Command types covered are DDL (for definitions), DML (for manipulations), and DCL (for control). The document provides an instructor and contact information, and concludes by stating the training will end after 7 days of content.
The document discusses various database concepts including:
1. DBMS, RDBMS, SQL, fields, records, tables, transactions, locks, normalization, primary keys, foreign keys, joins, views, stored procedures, triggers, and index types are discussed.
2. Key topics covered include the components and functions of a DBMS and RDBMS, the structure and purpose of SQL, database objects like tables and records, ensuring data integrity through transactions and locks, and optimizing database design through normalization.
3. Common operations on data like queries, inserts, updates, and deletes are explained along with advanced topics like views, stored procedures, triggers, and indexes.
A database management system (DBMS) is system software for creating and managing databases. The DBMS provides users and programmers with a systematic way to create, retrieve, update and manage data.
A DBMS makes it possible for end users to create, read, update and delete data in a database. The DBMS essentially serves as an interface between the database and end users or application programs, ensuring that data is consistently organized and remains easily accessible.Read more.........
- An object-relational database (ORD) or object-relational database management system (ORDBMS) supports objects, classes, and inheritance directly in the database schema and query language, while also retaining the relational model.
- An ORDBMS supports an extended form of SQL called SQL3 for handling abstract data types. It allows storage of complex data types like images and location data.
- Key advantages of ORDBMS include reuse and sharing of code through inheritance, increased productivity for developers and users, and more powerful query capabilities. Key challenges include complexity, immaturity of the technology, and increased costs.
This document provides an overview of SQL, including its objectives, history, data definition and manipulation languages, and basic concepts. It discusses SQL's purpose in creating database structures and performing tasks like inserts, updates, deletes, and queries. The document also covers SQL datatypes, keywords for queries, updates, and deletes, and both advantages and disadvantages of SQL.
This document discusses object-relational databases and how they extend relational databases to support complex data types and object-oriented features. It covers topics like nested relations, structured types, inheritance, and reference types. It provides examples of how to define complex types and values, perform queries using complex attributes, and map object-oriented concepts to the relational model.
A database is a collection of logically related data organized for convenient access and manipulation. A DBMS is a collection of programs that enables users to create and maintain a database, perform queries, and generate reports from the database. The database and DBMS together form a database system. Some key advantages of a DBMS include reducing data redundancy and inconsistency, enforcing data integrity, providing security, and facilitating data sharing among multiple users.
The document describes two case studies for developing entity-relationship (E-R) models. The first case study describes a university library scenario involving multiple libraries, student members of libraries, books within libraries, and inter-library loans. The second case study describes a banking business scenario involving multiple banks with branches, customers with various accounts and loans. The document then provides definitions and examples of keys, constraints, and other database concepts relevant to developing E-R models from case studies.
This document provides an overview of basic database concepts, characteristics of a database management system and relational database management system, data types used in databases, how to create tables and insert data. It discusses how a database stores organized data for a specific purpose, represents relationships between data, ensures data integrity and access authorization. It also describes how a relational database model uses tables to store data and supports querying and manipulating sets of data.
This document summarizes three papers on keyword search over structured databases using an interpretative approach. The first paper discusses building an efficient index table to map keywords to row and column identifiers in the database. The second paper presents a general algorithm with two steps - a publication step to pre-compute indexing, and a search step to lookup keywords and generate SQL queries. The third paper introduces the concept of intrinsic and contextual weights to model the dependency between query keywords and generate a ranked list of query interpretations.
The document provides an overview of relational database management system (RDBMS) concepts. It discusses what a database is, different database types like hierarchical, network, relational and object relational. It also explains the relational model proposed by Dr. E.F. Codd, how it uses tables, rows and columns. Key concepts covered include relationships, constraints, keys, normalization and transactions. Entity relationship modeling and diagramming are demonstrated through an example involving producers, depots, collection agents and procurement records.
This document provides an introduction to relational database management systems (RDBMS). It discusses the key components and functions of an RDBMS including data storage and retrieval, transaction support, concurrency control, and authorization services. Various database concepts are explained such as the relational model, normalization forms, indexing techniques like B+ trees and hashing, and concurrency control methods like locking. Transaction properties like atomicity, consistency, isolation, and durability are also covered. Join operations and views are defined. The document provides a high-level overview of fundamental RDBMS concepts.
A foreign key is a column that references the primary key of another table. It must match a value in the referenced primary key. Unlike primary keys, foreign keys can contain null values. Primary keys uniquely identify rows in a table, while foreign keys reference primary keys to link data between tables.
Object-Relational Database Systems(ORDBMSs) can successfully deal with very large data volumes with great complexity. At present the vendors of all the major DBMS products have supported object-relational database management systems, but still its industrial adoption rate is relatively low.
The document provides information about Structured Query Language (SQL) including its basic concepts, data types, CREATE TABLE and INSERT commands, constraints, operators and data modifications. It defines key SQL concepts such as relations, attributes, tuples, primary keys, foreign keys and discusses SQL's capabilities for data definition, manipulation, queries and transaction control. Examples are given for creating a table and inserting records into the table.
Overview of Object-Oriented Concepts Characteristics by vikas jagtapVikas Jagtap
Object-oriented data base systems are proposed as alternative to relational systems and are aimed at application domains where complex objects play a central role.
The approach is heavily influenced by object-oriented programming languages and can be understood as an attempt to add DBMS functionality to a programming language environment
Security of Social Information from Query Analysis in DaaSJunpei Kawamoto
This document discusses protecting social information inferred from database queries. It introduces the problem of attackers extracting social relationships between users from query logs. An attack model is presented where users querying similar topics are assumed to be related. The document then proposes a method of query conversion using an extendible hashing tree to map original queries to generalized queries. This aims to prevent determining the exact original queries and therefore the social relationships between users from the query logs. Evaluation of the method shows it can significantly reduce the precision and recall of the attack in determining social information.
This document provides instructions for performing a mail merge in Microsoft Word. It explains that a mail merge allows you to merge data from a source, like an Excel file or Access database, into a Word document to create customized documents. The document outlines the 5 steps to set up and perform a mail merge: 1) Set up the main document, 2) Connect the data source, 3) Refine the data, 4) Add merged fields, and 5) Preview and complete the merge. It also provides examples of how to create labels using the mail merge function.
The document provides an overview of database management systems (DBMS) and structured query language (SQL). It discusses that a DBMS allows for the creation, maintenance and control of access to a database. It also describes the basic processes supported by a DBMS, including storing, manipulating, querying and updating database content. The document then covers how data is organized in a database through concepts like database files, tables, records, fields and data types. It provides examples to illustrate these concepts. Finally, it describes the different types of SQL statements like data definition language, data manipulation language and database control language statements.
This document discusses fuzzy querying of relational databases. It begins by introducing fuzzy relational database management systems (FRDBMS), which allow imprecise queries using fuzzy logic. It then presents the basic concepts of fuzzy logic and membership functions. The architecture of an FRDBMS is described, including how it translates fuzzy queries into equivalent SQL queries. An example student database is used to demonstrate a fuzzy query for "poor performers" and how it returns more graded results than an exact SQL query. The document concludes that FRDBMS improves the expressiveness of queries over traditional databases.
This document discusses object query language (OQL) and the six-layer architecture model for object-oriented databases. It provides an overview of OQL, describing how it is based on SQL but extends it to support object-oriented notions. It also outlines the main components of the six-layer model - the interaction layer, application layer, administrative layer, security layer, virtual layer, and paging layer - and describes their basic responsibilities in managing and securing object-oriented data. Finally, it briefly lists some disadvantages of object-oriented database management systems.
A relational database contains a collection of tables that are linked together through defined relationships. Each table holds information about an entity or object and consists of rows called tuples and columns called attributes that make up the data about that entity. Relationships between entities are represented by links between tables and can take the form of one-to-one, one-to-many, or many-to-many. Constraints define rules for the data in tables to ensure accuracy and reliability. Indexes help optimize database performance by enabling faster data retrieval and queries. Views allow users to access structured data from one or more tables through a predefined SQL query.
This document discusses data structures and the C preprocessor. It defines data structures as organized ways to store data in a computer. Common data structures include arrays, stacks, queues, linked lists, and trees. The C preprocessor processes C programs before compilation by performing tasks like including header files, defining macros, and conditional compilation. Preprocessor directives start with # and are used to transform the code before the compiler sees it. Macros are a common preprocessor feature that allows text substitutions using identifiers.
Data massage! databases scaled from one to one million nodes (ulf wendel)Zhang Bo
The speaker provides an overview of databases and database concepts, beginning with a brief history from the 1960s when applications stored data in individual files. Database management systems were introduced in the 1970s to consolidate data. The speaker then discusses data modeling concepts like the entity-relationship model and database normalization. Key topics from the relational model are covered like SQL, transactions and concurrency control. Physical storage structures like B-trees and indexing are also mentioned briefly. The talk aims to provide background for both traditional and NoSQL databases.
Introduction to YQL - Talk at HackU 2010, IIT ChennaiBalaji Narayanan
YQL (Yahoo Query Language) provides a SQL-like language for accessing and manipulating data from diverse web sources. It allows developers to unify access to thousands of web services and data sources through a simple and familiar interface. YQL expressions can retrieve, filter, combine and transform data from any structured data source on the web or web services. This simplifies and standardizes data access for developers compared to reading documentation and constructing specific API calls for each source.
This document discusses location-based technologies and applications. It provides information on locating places based on coordinates, mapping places to hierarchical geographical data, identifying locations from social network activity, and examples of place-finding applications. It also includes links to additional geo-location and mapping APIs and resources. The document is presented by Balaji Narayanan and includes his contact information.
Hacking 101 - An Introduction to HackU at IIT KanpurBalaji Narayanan
This document provides guidance and resources for participating in a hack day event focused on coding and innovation. It encourages participants to focus on fixing something they use every day, building something for their own use, or making the world a better place. It recommends finding existing APIs and services to combine in new ways within a 24 hour timeframe. Yahoo and other sites are identified as having useful open data and tools like YQL and Pipes for accessing and combining multiple data sources. The document stresses the importance of having a working interface and publishing the hack online for others to see.
This document discusses object-relational databases and how they extend relational databases to support complex data types and object-oriented features. It covers topics like nested relations, structured types, inheritance, and reference types. It provides examples of how to define complex types and values, perform queries using complex attributes, and map object-oriented concepts to the relational model.
A database is a collection of logically related data organized for convenient access and manipulation. A DBMS is a collection of programs that enables users to create and maintain a database, perform queries, and generate reports from the database. The database and DBMS together form a database system. Some key advantages of a DBMS include reducing data redundancy and inconsistency, enforcing data integrity, providing security, and facilitating data sharing among multiple users.
The document describes two case studies for developing entity-relationship (E-R) models. The first case study describes a university library scenario involving multiple libraries, student members of libraries, books within libraries, and inter-library loans. The second case study describes a banking business scenario involving multiple banks with branches, customers with various accounts and loans. The document then provides definitions and examples of keys, constraints, and other database concepts relevant to developing E-R models from case studies.
This document provides an overview of basic database concepts, characteristics of a database management system and relational database management system, data types used in databases, how to create tables and insert data. It discusses how a database stores organized data for a specific purpose, represents relationships between data, ensures data integrity and access authorization. It also describes how a relational database model uses tables to store data and supports querying and manipulating sets of data.
This document summarizes three papers on keyword search over structured databases using an interpretative approach. The first paper discusses building an efficient index table to map keywords to row and column identifiers in the database. The second paper presents a general algorithm with two steps - a publication step to pre-compute indexing, and a search step to lookup keywords and generate SQL queries. The third paper introduces the concept of intrinsic and contextual weights to model the dependency between query keywords and generate a ranked list of query interpretations.
The document provides an overview of relational database management system (RDBMS) concepts. It discusses what a database is, different database types like hierarchical, network, relational and object relational. It also explains the relational model proposed by Dr. E.F. Codd, how it uses tables, rows and columns. Key concepts covered include relationships, constraints, keys, normalization and transactions. Entity relationship modeling and diagramming are demonstrated through an example involving producers, depots, collection agents and procurement records.
This document provides an introduction to relational database management systems (RDBMS). It discusses the key components and functions of an RDBMS including data storage and retrieval, transaction support, concurrency control, and authorization services. Various database concepts are explained such as the relational model, normalization forms, indexing techniques like B+ trees and hashing, and concurrency control methods like locking. Transaction properties like atomicity, consistency, isolation, and durability are also covered. Join operations and views are defined. The document provides a high-level overview of fundamental RDBMS concepts.
A foreign key is a column that references the primary key of another table. It must match a value in the referenced primary key. Unlike primary keys, foreign keys can contain null values. Primary keys uniquely identify rows in a table, while foreign keys reference primary keys to link data between tables.
Object-Relational Database Systems(ORDBMSs) can successfully deal with very large data volumes with great complexity. At present the vendors of all the major DBMS products have supported object-relational database management systems, but still its industrial adoption rate is relatively low.
The document provides information about Structured Query Language (SQL) including its basic concepts, data types, CREATE TABLE and INSERT commands, constraints, operators and data modifications. It defines key SQL concepts such as relations, attributes, tuples, primary keys, foreign keys and discusses SQL's capabilities for data definition, manipulation, queries and transaction control. Examples are given for creating a table and inserting records into the table.
Overview of Object-Oriented Concepts Characteristics by vikas jagtapVikas Jagtap
Object-oriented data base systems are proposed as alternative to relational systems and are aimed at application domains where complex objects play a central role.
The approach is heavily influenced by object-oriented programming languages and can be understood as an attempt to add DBMS functionality to a programming language environment
Security of Social Information from Query Analysis in DaaSJunpei Kawamoto
This document discusses protecting social information inferred from database queries. It introduces the problem of attackers extracting social relationships between users from query logs. An attack model is presented where users querying similar topics are assumed to be related. The document then proposes a method of query conversion using an extendible hashing tree to map original queries to generalized queries. This aims to prevent determining the exact original queries and therefore the social relationships between users from the query logs. Evaluation of the method shows it can significantly reduce the precision and recall of the attack in determining social information.
This document provides instructions for performing a mail merge in Microsoft Word. It explains that a mail merge allows you to merge data from a source, like an Excel file or Access database, into a Word document to create customized documents. The document outlines the 5 steps to set up and perform a mail merge: 1) Set up the main document, 2) Connect the data source, 3) Refine the data, 4) Add merged fields, and 5) Preview and complete the merge. It also provides examples of how to create labels using the mail merge function.
The document provides an overview of database management systems (DBMS) and structured query language (SQL). It discusses that a DBMS allows for the creation, maintenance and control of access to a database. It also describes the basic processes supported by a DBMS, including storing, manipulating, querying and updating database content. The document then covers how data is organized in a database through concepts like database files, tables, records, fields and data types. It provides examples to illustrate these concepts. Finally, it describes the different types of SQL statements like data definition language, data manipulation language and database control language statements.
This document discusses fuzzy querying of relational databases. It begins by introducing fuzzy relational database management systems (FRDBMS), which allow imprecise queries using fuzzy logic. It then presents the basic concepts of fuzzy logic and membership functions. The architecture of an FRDBMS is described, including how it translates fuzzy queries into equivalent SQL queries. An example student database is used to demonstrate a fuzzy query for "poor performers" and how it returns more graded results than an exact SQL query. The document concludes that FRDBMS improves the expressiveness of queries over traditional databases.
This document discusses object query language (OQL) and the six-layer architecture model for object-oriented databases. It provides an overview of OQL, describing how it is based on SQL but extends it to support object-oriented notions. It also outlines the main components of the six-layer model - the interaction layer, application layer, administrative layer, security layer, virtual layer, and paging layer - and describes their basic responsibilities in managing and securing object-oriented data. Finally, it briefly lists some disadvantages of object-oriented database management systems.
A relational database contains a collection of tables that are linked together through defined relationships. Each table holds information about an entity or object and consists of rows called tuples and columns called attributes that make up the data about that entity. Relationships between entities are represented by links between tables and can take the form of one-to-one, one-to-many, or many-to-many. Constraints define rules for the data in tables to ensure accuracy and reliability. Indexes help optimize database performance by enabling faster data retrieval and queries. Views allow users to access structured data from one or more tables through a predefined SQL query.
This document discusses data structures and the C preprocessor. It defines data structures as organized ways to store data in a computer. Common data structures include arrays, stacks, queues, linked lists, and trees. The C preprocessor processes C programs before compilation by performing tasks like including header files, defining macros, and conditional compilation. Preprocessor directives start with # and are used to transform the code before the compiler sees it. Macros are a common preprocessor feature that allows text substitutions using identifiers.
Data massage! databases scaled from one to one million nodes (ulf wendel)Zhang Bo
The speaker provides an overview of databases and database concepts, beginning with a brief history from the 1960s when applications stored data in individual files. Database management systems were introduced in the 1970s to consolidate data. The speaker then discusses data modeling concepts like the entity-relationship model and database normalization. Key topics from the relational model are covered like SQL, transactions and concurrency control. Physical storage structures like B-trees and indexing are also mentioned briefly. The talk aims to provide background for both traditional and NoSQL databases.
Introduction to YQL - Talk at HackU 2010, IIT ChennaiBalaji Narayanan
YQL (Yahoo Query Language) provides a SQL-like language for accessing and manipulating data from diverse web sources. It allows developers to unify access to thousands of web services and data sources through a simple and familiar interface. YQL expressions can retrieve, filter, combine and transform data from any structured data source on the web or web services. This simplifies and standardizes data access for developers compared to reading documentation and constructing specific API calls for each source.
This document discusses location-based technologies and applications. It provides information on locating places based on coordinates, mapping places to hierarchical geographical data, identifying locations from social network activity, and examples of place-finding applications. It also includes links to additional geo-location and mapping APIs and resources. The document is presented by Balaji Narayanan and includes his contact information.
Hacking 101 - An Introduction to HackU at IIT KanpurBalaji Narayanan
This document provides guidance and resources for participating in a hack day event focused on coding and innovation. It encourages participants to focus on fixing something they use every day, building something for their own use, or making the world a better place. It recommends finding existing APIs and services to combine in new ways within a 24 hour timeframe. Yahoo and other sites are identified as having useful open data and tools like YQL and Pipes for accessing and combining multiple data sources. The document stresses the importance of having a working interface and publishing the hack online for others to see.
The document discusses BOSS (Build Your Own Search Service), an API interface that allows users to access data stores for search functions. It can retrieve data from multiple sources like news, web, and images. The BOSS API can be used to change presentation styles, re-order results, and blend in additional content. It also discusses monetizing search results and references various BOSS tools and the speaker's background.
The document provides 5 things for developers including: 1) Research resources on Yahoo patterns, performance, and YUI; 2) Flexible professional development with YUI; 3) Documentation; 4) Things to impress bosses like search and YSlow; and 5) Partnering by using custom YQL tables.
OAuth Dance - Yahoo! Open Hack Day Bangalore, 2011Balaji Narayanan
OAuth is an open protocol that allows secure authorization from applications to APIs using tokens instead of passwords. It allows users to share data without sharing their identity or credentials, providing applications with temporary delegated access tokens that can be revoked. The protocol is API independent and supports single user identity across multiple applications and services.
YQL - A swiss army knife for your hacks at HackU 2010, IIT BombayBalaji Narayanan
YQL is a web service that allows users to access and manipulate data from APIs and web services using a SQL-like language. It acts as a "swiss army knife" for developers by providing a single interface to query, filter, join, and update data across thousands of structured data sources on the web without having to learn each individual API. The presentation encourages developers to use YQL for their projects as it handles the complexity of interacting with different data sources and lets them focus on building their applications.
The document provides an overview of SQL (Structured Query Language) and relational databases. It defines what a database and RDBMS are, explains that SQL is the standard language for communicating with relational databases, and distinguishes SQL from MySQL. The summary then provides an overview of the key topics covered in the document, which include creating and interacting with database tables using SQL commands like SELECT, INSERT, UPDATE, and DELETE.
Big Data is used to store huge volume of both structured and unstructured data which is so large and is
hard to process using current / traditional database tools and software technologies. The goal of Big Data
Storage Management is to ensure a high level of data quality and availability for business intellect and big
data analytics applications. Graph database which is not most popular NoSQL database compare to
relational database yet but it is a most powerful NoSQL database which can handle large volume of data in
very efficient way. It is very difficult to manage large volume of data using traditional technology. Data
retrieval time may be more as per database size gets increase. As solution of that NoSQL databases are
available. This paper describe what is big data storage management, dimensions of big data, types of data,
what is structured and unstructured data, what is NoSQL database, types of NoSQL database, basic
structure of graph database, advantages, disadvantages and application area and comparison of various
graph database.
Big Data is used to store huge volume of both structured and unstructured data which is so large and is
hard to process using current / traditional database tools and software technologies. The goal of Big Data
Storage Management is to ensure a high level of data quality and availability for business intellect and big
data analytics applications. Graph database which is not most popular NoSQL database compare to
relational database yet but it is a most powerful NoSQL database which can handle large volume of data in
very efficient way. It is very difficult to manage large volume of data using traditional technology. Data
retrieval time may be more as per database size gets increase. As solution of that NoSQL databases are
available. This paper describe what is big data storage management, dimensions of big data, types of data,
what is structured and unstructured data, what is NoSQL database, types of NoSQL database, basic
structure of graph database, advantages, disadvantages and application area and comparison of various
graph database.
A Study on Graph Storage Database of NOSQLIJSCAI Journal
Big Data is used to store huge volume of both structured and unstructured data which is so large and is
hard to process using current / traditional database tools and software technologies. The goal of Big Data
Storage Management is to ensure a high level of data quality and availability for business intellect and big
data analytics applications. Graph database which is not most popular NoSQL database compare to
relational database yet but it is a most powerful NoSQL database which can handle large volume of data in
very efficient way. It is very difficult to manage large volume of data using traditional technology. Data
retrieval time may be more as per database size gets increase. As solution of that NoSQL databases are
available. This paper describe what is big data storage management, dimensions of big data, types of data,
what is structured and unstructured data, what is NoSQL database, types of NoSQL database, basic
structure of graph database, advantages, disadvantages and application area and comparison of various
graph database.
A Study on Graph Storage Database of NOSQLIJSCAI Journal
This document summarizes a research paper on graph storage databases in NoSQL. It discusses big data and the need for alternative databases to handle large, diverse datasets. It defines the key aspects of big data including volume, velocity, variety and complexity. It also describes different types of NoSQL databases, focusing on the basic structure of graph databases. Graph databases use nodes and relationships to model connected data. The document compares several graph database systems and discusses advantages like performance and flexibility as well as disadvantages like complexity. It outlines several applications of graph databases in areas like social networks and logistics.
1) Organizations now deal with huge amounts of data both internally and externally generated to better understand their business and customers.
2) Relational databases cannot effectively handle this big data due to challenges in data structure, scaling, and speed.
3) NoSQL databases provide alternatives to store structured, semi-structured, and unstructured data across different data models like columnar, key-value, document, and graph. Each type has different properties suited for various use cases.
This document discusses revisiting SQL basics and advanced topics. It covers objectives, assumptions, and topics to be covered including staying clean with conventions, data types, revisiting basics, joining, subqueries, joins versus subqueries, group by, set operations, and case statements. The topics sections provides details on each topic with examples to enhance SQL knowledge and write better queries.
What Your Database Query is Really DoingDave Stokes
Do you ever wonder what your database servers is REALLY doing with that query you just wrote. This is a high level overview of the process of running a query
This document provides an introduction and overview of NoSQL concepts and MongoDB database. It begins with the purpose of guiding beginners and discusses how the growth of data led to the development of NoSQL technologies. It then covers the history of databases, defines key terms, and describes the different types of NoSQL databases like key-value, column-oriented, document-oriented and graph oriented. Specifics about MongoDB are provided, including conceptual understanding, basic operations like insert and find, and comparison operators. The document aims to make learning MongoDB and NoSQL easy and fun for beginners.
Structured Query Language (SQL) _ Edu4Sure Training.pptxEdu4Sure
The PPT content is for reference only. The training will be hands-on & practical.
Training: SQL (Structured Query Language)
For any Training & Certificate, please email us at partner@edu4sure.com
or Call/ whatsapp at +91-9555115533
Or visit www.testformula.com (Our LMS to access Self-paced vidoes) or visit www.edu4sure.com
The student will understand the basics of the Relational Database Model.
The student will learn Database Administration functions as appropriate for software developers.
The student will learn SQL.
The student will become familiar with the entire implementation cycle of a client server application.
And, you will build one.
This document provides an overview of NoSQL databases. It discusses that NoSQL databases offer more flexibility, higher performance, scalability, and choices compared to relational databases. The four main types of NoSQL databases are column family stores, key-value stores, document stores, and graph stores. Each has their own advantages and disadvantages for storing and querying data.
Data massage: How databases have been scaled from one to one million nodesUlf Wendel
A workshop from the PHP Summit 2013, Berlin.
Join me on a journey to scaling databases from one to one million nodes. The adventure begins in the 1960th and ends with Google Spanner details from a Google engineer's talk given as late as November 25th, 2013!
Contents: Relational systems and caching (briefly), what CAP means, Overlay networks, Distributed Hash Tables (Chord), Amazon Dynamo, Riak 2.0 including CRDT, BigTable (Distributed File System, Distributed Locking Service), HBase (Hive, Presto, Impala, ...), Google Spanner and how their unique TrueTime API enables ACID, what CAP really means to ACID transactions (and the NoSQL marketing fuzz), the latest impact of NoSQL on the RDBMS world. There're quite a bit of theory in the talk, but that's how things go when you walk between Distributed Systems Theory and Theory of Parallel and Distributed Databases, such as.... Two-Phase Commit, Two-Phase Locking, Virtual Synchrony, Atomic Broadcast, FLP Impossibility Theorem, Paxos, Co-Location and data models...
The document discusses various data types in Microsoft Access including text, number, auto number, date/time, yes/no, currency, memo, OLE object, hyperlink, and lookup wizard. It provides descriptions of each data type, what kind of data they can store, and their storage capacities. For example, it notes that text can store up to 255 characters in 2 bytes, numbers can store values between -32768 to 32767 in 4 bytes, and auto number automatically generates numbers.
The document provides an overview of the SQL programming language. It describes SQL as a language used to manage and retrieve data from relational databases. It then covers SQL fundamentals including basic SQL commands, data types, operators, and expressions. Examples are provided throughout to illustrate concepts.
This document provides an overview of the SQL programming language. It defines SQL as a language used to manage and retrieve data from relational databases. It describes the basic SQL commands like SELECT, INSERT, UPDATE, DELETE, and explains the different data types that can be used in SQL like numeric, character, and date/time. It also gives examples of basic SQL statements and clauses.
This document provides an overview of NoSQL databases. It discusses that NoSQL databases are non-relational and were created to overcome limitations of scaling relational databases. The document categorizes NoSQL databases into key-value stores, document databases, graph databases, XML databases, and distributed peer stores. It provides examples like MongoDB, Redis, CouchDB, and Cassandra. The document also explains concepts like CAP theorem, ACID properties, and reasons for using NoSQL databases like horizontal scaling, schema flexibility, and handling large amounts of data.
This document discusses database management system (DBMS) architecture and relational database management systems (RDBMS). It describes one-tier, two-tier, and three-tier architectures for DBMS. It also discusses database models including hierarchical, network, and relational models. Additionally, it covers RDBMS concepts such as tables, records, fields, columns, keys including primary keys and foreign keys. It provides examples to illustrate these concepts.
Threats to mobile devices are more prevalent and increasing in scope and complexity. Users of mobile devices desire to take full advantage of the features
available on those devices, but many of the features provide convenience and capability but sacrifice security. This best practices guide outlines steps the users can take to better protect personal devices and information.
Skybuffer SAM4U tool for SAP license adoptionTatiana Kojar
Manage and optimize your license adoption and consumption with SAM4U, an SAP free customer software asset management tool.
SAM4U, an SAP complimentary software asset management tool for customers, delivers a detailed and well-structured overview of license inventory and usage with a user-friendly interface. We offer a hosted, cost-effective, and performance-optimized SAM4U setup in the Skybuffer Cloud environment. You retain ownership of the system and data, while we manage the ABAP 7.58 infrastructure, ensuring fixed Total Cost of Ownership (TCO) and exceptional services through the SAP Fiori interface.
Project Management Semester Long Project - Acuityjpupo2018
Acuity is an innovative learning app designed to transform the way you engage with knowledge. Powered by AI technology, Acuity takes complex topics and distills them into concise, interactive summaries that are easy to read & understand. Whether you're exploring the depths of quantum mechanics or seeking insight into historical events, Acuity provides the key information you need without the burden of lengthy texts.
OpenID AuthZEN Interop Read Out - AuthorizationDavid Brossard
During Identiverse 2024 and EIC 2024, members of the OpenID AuthZEN WG got together and demoed their authorization endpoints conforming to the AuthZEN API
How to Get CNIC Information System with Paksim Ga.pptxdanishmna97
Pakdata Cf is a groundbreaking system designed to streamline and facilitate access to CNIC information. This innovative platform leverages advanced technology to provide users with efficient and secure access to their CNIC details.
Ivanti’s Patch Tuesday breakdown goes beyond patching your applications and brings you the intelligence and guidance needed to prioritize where to focus your attention first. Catch early analysis on our Ivanti blog, then join industry expert Chris Goettl for the Patch Tuesday Webinar Event. There we’ll do a deep dive into each of the bulletins and give guidance on the risks associated with the newly-identified vulnerabilities.
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceIndexBug
Imagine a world where machines not only perform tasks but also learn, adapt, and make decisions. This is the promise of Artificial Intelligence (AI), a technology that's not just enhancing our lives but revolutionizing entire industries.
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUpanagenda
Webinar Recording: https://www.panagenda.com/webinars/hcl-notes-und-domino-lizenzkostenreduzierung-in-der-welt-von-dlau/
DLAU und die Lizenzen nach dem CCB- und CCX-Modell sind für viele in der HCL-Community seit letztem Jahr ein heißes Thema. Als Notes- oder Domino-Kunde haben Sie vielleicht mit unerwartet hohen Benutzerzahlen und Lizenzgebühren zu kämpfen. Sie fragen sich vielleicht, wie diese neue Art der Lizenzierung funktioniert und welchen Nutzen sie Ihnen bringt. Vor allem wollen Sie sicherlich Ihr Budget einhalten und Kosten sparen, wo immer möglich. Das verstehen wir und wir möchten Ihnen dabei helfen!
Wir erklären Ihnen, wie Sie häufige Konfigurationsprobleme lösen können, die dazu führen können, dass mehr Benutzer gezählt werden als nötig, und wie Sie überflüssige oder ungenutzte Konten identifizieren und entfernen können, um Geld zu sparen. Es gibt auch einige Ansätze, die zu unnötigen Ausgaben führen können, z. B. wenn ein Personendokument anstelle eines Mail-Ins für geteilte Mailboxen verwendet wird. Wir zeigen Ihnen solche Fälle und deren Lösungen. Und natürlich erklären wir Ihnen das neue Lizenzmodell.
Nehmen Sie an diesem Webinar teil, bei dem HCL-Ambassador Marc Thomas und Gastredner Franz Walder Ihnen diese neue Welt näherbringen. Es vermittelt Ihnen die Tools und das Know-how, um den Überblick zu bewahren. Sie werden in der Lage sein, Ihre Kosten durch eine optimierte Domino-Konfiguration zu reduzieren und auch in Zukunft gering zu halten.
Diese Themen werden behandelt
- Reduzierung der Lizenzkosten durch Auffinden und Beheben von Fehlkonfigurationen und überflüssigen Konten
- Wie funktionieren CCB- und CCX-Lizenzen wirklich?
- Verstehen des DLAU-Tools und wie man es am besten nutzt
- Tipps für häufige Problembereiche, wie z. B. Team-Postfächer, Funktions-/Testbenutzer usw.
- Praxisbeispiele und Best Practices zum sofortigen Umsetzen
HCL Notes and Domino License Cost Reduction in the World of DLAUpanagenda
Webinar Recording: https://www.panagenda.com/webinars/hcl-notes-and-domino-license-cost-reduction-in-the-world-of-dlau/
The introduction of DLAU and the CCB & CCX licensing model caused quite a stir in the HCL community. As a Notes and Domino customer, you may have faced challenges with unexpected user counts and license costs. You probably have questions on how this new licensing approach works and how to benefit from it. Most importantly, you likely have budget constraints and want to save money where possible. Don’t worry, we can help with all of this!
We’ll show you how to fix common misconfigurations that cause higher-than-expected user counts, and how to identify accounts which you can deactivate to save money. There are also frequent patterns that can cause unnecessary cost, like using a person document instead of a mail-in for shared mailboxes. We’ll provide examples and solutions for those as well. And naturally we’ll explain the new licensing model.
Join HCL Ambassador Marc Thomas in this webinar with a special guest appearance from Franz Walder. It will give you the tools and know-how to stay on top of what is going on with Domino licensing. You will be able lower your cost through an optimized configuration and keep it low going forward.
These topics will be covered
- Reducing license cost by finding and fixing misconfigurations and superfluous accounts
- How do CCB and CCX licenses really work?
- Understanding the DLAU tool and how to best utilize it
- Tips for common problem areas, like team mailboxes, functional/test users, etc
- Practical examples and best practices to implement right away
Introduction of Cybersecurity with OSS at Code Europe 2024Hiroshi SHIBATA
I develop the Ruby programming language, RubyGems, and Bundler, which are package managers for Ruby. Today, I will introduce how to enhance the security of your application using open-source software (OSS) examples from Ruby and RubyGems.
The first topic is CVE (Common Vulnerabilities and Exposures). I have published CVEs many times. But what exactly is a CVE? I'll provide a basic understanding of CVEs and explain how to detect and handle vulnerabilities in OSS.
Next, let's discuss package managers. Package managers play a critical role in the OSS ecosystem. I'll explain how to manage library dependencies in your application.
I'll share insights into how the Ruby and RubyGems core team works to keep our ecosystem safe. By the end of this talk, you'll have a better understanding of how to safeguard your code.
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfChart Kalyan
A Mix Chart displays historical data of numbers in a graphical or tabular form. The Kalyan Rajdhani Mix Chart specifically shows the results of a sequence of numbers over different periods.
For the full video of this presentation, please visit: https://www.edge-ai-vision.com/2024/06/building-and-scaling-ai-applications-with-the-nx-ai-manager-a-presentation-from-network-optix/
Robin van Emden, Senior Director of Data Science at Network Optix, presents the “Building and Scaling AI Applications with the Nx AI Manager,” tutorial at the May 2024 Embedded Vision Summit.
In this presentation, van Emden covers the basics of scaling edge AI solutions using the Nx tool kit. He emphasizes the process of developing AI models and deploying them globally. He also showcases the conversion of AI models and the creation of effective edge AI pipelines, with a focus on pre-processing, model conversion, selecting the appropriate inference engine for the target hardware and post-processing.
van Emden shows how Nx can simplify the developer’s life and facilitate a rapid transition from concept to production-ready applications.He provides valuable insights into developing scalable and efficient edge AI solutions, with a strong focus on practical implementation.
Best 20 SEO Techniques To Improve Website Visibility In SERPPixlogix Infotech
Boost your website's visibility with proven SEO techniques! Our latest blog dives into essential strategies to enhance your online presence, increase traffic, and rank higher on search engines. From keyword optimization to quality content creation, learn how to make your site stand out in the crowded digital landscape. Discover actionable tips and expert insights to elevate your SEO game.
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Sql and mysql database concepts
1. A Tutorial on Database Concepts, SQL using MySQL.
Home
This tutorial may be reproduced without any modifications to this document for non-commercial,
non-profit purposes.
All other forms of usage requires the permission of the author - Ranjan Chari, email:
ranjan@atlasindia.com
This tutorial aims to provide the reader with the following:
• A lucid and quick understanding of databases, RDBMS and related jargon such as triggers,
replication, procedures etc.
• A clear understanding of how SQL works.
• Lots of examples with SQL using MySQL that make understanding the process of
contructing SQL queries easy and also using MySQL and to illustrate the mechanism of
storing and retrieving information from databases.
(If you find any errors, please send me an email and I'll promptly set it right. If there's something
you'd like to see here let me know too.)
What's a database ?
A database is a collection of data organized in a particular way.
Databases can be of many types such as Flat File Databases, Relational Databases, Distributed
Databases etc.
What's SQL ?
In 1971, IBM researchers created a simple non-procedural language called Structured English
Query Language. or SEQUEL. This was based on Dr. Edgar F. (Ted) Codd's design of a relational
model for data storage where he described a universal programming language for accessing
databases.
In the late 80's ANSI and ISO (these are two organizations dealing with standards for a wide
variety of things) came out with a standardized version called Structured Query Language or SQL.
SQL is prounced as 'Sequel'. There have been several versions of SQL and the latest one is
SQL-99. Though SQL-92 is the current universally adopted standard.
SQL is the language used to query all databases. It's simple to learn and appears to do very little
but is the heart of a successful database application. Understanding SQL and using it efficiently is
highly imperative in designing an efficient database application. The better your understanding of
SQL the more versatile you'll be in getting information out of databases.
What's an RDBMS ?
This concept was first described around 1970 by Dr. Edgar F. Codd in an IBM research publication
called "System R4 Relational".
A relational database uses the concept of linked two-dimensional tables which comprise of rows
and columns. A user can draw relationships between multiple tables and present the output as a
table again. A user of a relational database need not understand the representation of data in
order to retrieve it. Relational programming is non-procedural.
2. [What's procedural and non-procedural ?
Programming languages are procedural if they use programming elements such as conditional
statements (if-then-else, do-while etc.). SQL has none of these types of statements.]
In 1979, Relational Software released the world's first relational database called Oracle V.2
What a DBMS ?
MySQL and mSQL are database management systems or DBMS. These software packages are
used to manipulate a database. All DBMSs use their own implementation of SQL. It may be a
subset or a superset of the instructions provided by SQL 92.
MySQL, due to it's simplicity uses a subset of SQL 92 (also known as SQL2).
What's Database Normalization ?
Normalization is the process where a database is designed in a way that removes redundancies,
and increases the clarity in organizing data in a database.
In easy English, it means take similar stuff out of a collection of data and place them into tables.
Keep doing this for each new table recursively and you'll have a Normalized database. From this
resultant database you should be able to recreate the data into it's original state if there is a need
to do so.
The important thing here is to know when to Normalize and when to be practical. That will come
with experience. For now, read on...
Normalization of a database helps in modifying the design at later times and helps in being
prepared if a change is required in the database design. Normalization raises the efficiency of the
datatabase in terms of management, data storage and scalability.
Now Normalization of a Database is achieved by following a set of rules called 'forms' in creating
the database.
These rules are 5 in number (with one extra one stuck in-between 3&4) and they are:
1st Normal Form or 1NF:
Each Column Type is Unique.
2nd Normal Form or 2NF:
The entity under consideration should already be in the 1NF and all attributes within the entity
should depend solely on the entity's unique identifier.
3rd Normal Form or 3NF:
The entity should already be in the 2NF and no column entry should be dependent on any other
entry (value) other than the key for the table.
If such an entity exists, move it outside into a new table.
Now if these 3NF are achieved, the database is considered normalized. But there are three more
'extended' NF for the elitist.
These are:
BCNF (Boyce & Codd):
The database should be in 3NF and all tables can have only one primary key.
4NF:
Tables cannot have multi-valued dependencies on a Primary Key.
5NF:
3. There should be no cyclic dependencies in a composite key.
Well this is a highly simplified explanation for Database Normalization. One can study this process
extensively though. After working with databases for some time you'll automatically create
Normalized databases. As, it's logical and practical.
For now, don't worry too much about Normalization. The quickest way to grasp SQL and
Databases is to plunge headlong into creating tables and start messing around with SQL
statements. After you go through the tutorial examples and also the example contacts database,
look at the example provided in creating a normalized database near the very end of this tutorial.
And then try to think how you would like to create your own database.
Much of database design depends on how YOU want to keep the data. In real life situations often
you may find it more convenient to store data in tables designed in a way that does fall a bit short
of keeping all the NFs happy. But that's what databases are all about. Making your life simpler.
Onto SQL
There are four basic commands which are the workhorses for SQL and figure in almost all queries
to a database.
INSERT - Insert Data
DELETE - Delete Data
SELECT - Pull Data
UPDATE - Change existing Data
As you can see SQL is like English.
Let's build a real world example database using MySQL and perform some SQL operations on it.
A database that practically anyone could use would be a Contacts database.
In our example we are going to create create a database with the following fields:
• FirstName
• LastName
• BirthDate
• StreetAddress
• City
• State
• Zip
• Country
• TelephoneHome
• TelephoneWork
• Email
• CompanyName
• Designation
First, lets decide how we are going to store this data in the database. For illustration
4. purposes, we are going to keep this data in multiple tables.
This will let us exercise all of the SQL commands pertaining to retrieving data from multiple
tables. Also we can separate different kinds of entities into different tables. So let's say you have
thousands of friends and need to send a mass email to all of them, a SELECT statement (covered
later) will look at only one table.
Well, we can keep the FirstName, LastName and BirthDate in one table.
Address related data in another.
Company Details in another.
Emails can be separated into another.
Telephones can be separated into another.
Let's build the database in MySQL.
While building a database - you need to understand the concept of data types. Data types allow
the user to define how data is stored in fields or cells within a database. It's a way to define how
your data will actually exist. Whether it's a Date or a string consisting of 20 characters, an integer
etc. When we build tables within a database we also define the contents of each field in each row
in the table using a data type. It's imperative that you use only the data type that fits your needs
and don't use a data type that reserves more memory than the data in the field actually requires.
Let's look at various Data Types under MySQL.
Size in
Type Description
bytes
Integer with unsigned range of 0-255 and a signed range
TINYINT (length) 1
from -128-127
Integer with unsigned range of 0-65535 and a signed
SMALLINT (length) 2
range from -32768-32767
Integer with unsigned range of 0-16777215 and a signed
MEDIUMINT(length) 3
range from -8388608-8388607
Integer with unsigned range of 0-429467295 and a signed
INT(length) 4
range from -2147483648-2147483647
Integer with unsigned range of 0-18446744 and a signed
BIGINT(length) 8 range from
-9223372036854775808-9223372036854775807
Floating point number with max. value
FLOAT(length, decimal) 4 +/-3.402823466E38 and min.(non-zero) value
+/11.175494351E-38
Floating point number with max. value +/-
DOUBLEPRECISION(lengt
8 -1.7976931348623157E308 and min. (non-zero) value
h, decimal)
+/-2.2250738585072014E-308
DECIMAL(length, Floating point number with the range of the DOUBLE type
length
decimal) that is stored as a CHAR field type.
YYYYMMDDHHMMSS or YYMMDDHHMMSS or YYYYMMDD,
YYMMDD. A Timestamp value is updated each time the row
TIMESTAMP(length) 4
changes value. A NULL value sets the field to the current
time.
DATE 3 YYYY-MM-DD
TIME 3 HH:MM:DD
DATETIME 8 YYYY-MM-DD HH:MM:SS
YEAR 1 YYYY or YY
5. A fixed length text string where fields shorter than the
CHAR(length) length
assigned length are filled with trailing spaces.
A fixed length text string (255 Character Max) where
VARCHAR(length) length
unused trailing spaces are removed before storing.
length+
TINYTEXT A text field with max. length of 255 characters.
1
length+
TINYBLOB A binary field with max. length of 255 characters.
1
length+
TEXT 64Kb of text
1
length+
BLOB 64Kb of data
1
length+
MEDIUMTEXT 16Mb of text
3
length+
MEDIUMBLOB 16 Mb of data
3
length+
LONGTEXT 4GB of text
4
length+
LONGBLOB 4GB of data
4
This field can contain one of a possible 65535 number of
ENUM 1,2
options. Ex: ENUM('abc','def','ghi')
This type of field can contain any number of a set of
SET 1-8
predefined possible values.
The following examples will make things quite clear on declaring Data Types within SQL
statements.
Steps in Creating the Database using MySQL
From the shell prompt (either in DOS or UNIX):
mysqladmin create contacts;
This will create an empty database called "contacts".
Now run the command line tool "mysql" and from the mysql prompt do the following:
mysql> use contacts;
(You'll get the response "Database changed")
The following commands entered into the MySQL prompt will create the tables in the database.
mysql> CREATE TABLE names (contact_id SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName CHAR(20),
LastName CHAR(20), BirthDate DATE);
mysql> CREATE TABLE address(contact_id SMALLINT NOT NULL PRIMARY KEY, StreetAddress CHAR(50), City CHAR(20),
State CHAR(20), Zip CHAR(15), Country CHAR(20));
mysql> CREATE TABLE telephones (contact_id SMALLINT NOT NULL PRIMARY KEY, TelephoneHome CHAR(20),
TelephoneWork(20));
mysql> CREATE TABLE email (contact_id SMALLINT NOT NULL PRIMARY KEY, Email CHAR(20));
mysql> CREATE TABLE company_details (contact_id SMALLINT NOT NULL PRIMARY KEY, CompanyName CHAR(25),
Designation CHAR(15));
Note: Here we assume that one person will have only one email address. Now if there were a
situation where one person has multiple addresses, this design would be a problem. We'd need
another field which would keep values that indicated to whom the email address belonged to. In
6. this particular case email data ownership is indicated by the primary key. The same is true for
telephones. We are assuming that one person has only one home telephone and one work
telephone number. This need not be true. Similarly one person could work for multiple companies
at the same time holding two different designation. In all these cases an extra field will solve the
issue. For now however let's work with this small design.
KEYS:
The relationships between columns located in different tables are usually described through the
use of keys.
As you can see we have a PRIMARY KEY in each table. The Primary key serves as a mechanism to
refer to other fields within the same row. In this case, the Primary key is used to identify a
relationship between a row under consideration and the person whose name is located inside the
'names' table. We use the AUTO_INCREMENT statement only for the 'names' table as we need to
use the generated contact_id number in all the other tables for identification of the rows.
This type of table design where one table establishes a relationship with several other tables is
known as a 'one to many' relationship.
In a 'many to many' relationship we could have several Auto Incremented Primary Keys in
various tables with several inter-relationships.
Foreign Key:
A foreign key is a field in a table which is also the Primary Key in another table. This is known
commonly as 'referential integrity'.
Execute the following commands to see the newly created tables and their contents.
To see the tables inside the database:
mysql> SHOW TABLES;
+-----------------------+
| Tables in contacts |
+-----------------------+
| address |
| company_details |
| email |
| names |
| telephones |
+----------------------+
5 rows in set (0.00 sec)
To see the columns within a particular table:
mysql>SHOW COLUMNS FROM address;
+---------------+-------------+------+-----+---------+-------+---------------------------------+
| Field | Type | Null | Key | Default | Extra | Privileges
|
+---------------+-------------+------+-----+---------+-------+---------------------------------+
| contact_id | smallint(6) | | PRI | 0 | | select,insert,update,references |
| StreetAddress | char(50) | YES | | NULL | | select,insert,update,references |
| City | char(20) | YES | | NULL | | select,insert,update,references |
| State | char(20) | YES | | NULL | | select,insert,update,references |
| Zip | char(10) | YES | | NULL | | select,insert,update,references |
| Country | char(20) | YES | | NULL | | select,insert,update,references |
+---------------+-------------+------+-----+---------+-------+------------------ ---------------+
6 rows in set (0.00 sec)
So we have the tables created and ready. Now we put in some data.
Let's start with the 'names' table as it uses a unique AUTO_INCREMENT field which in turn is used
in the other tables.
Inserting data, one row at a time:
mysql> INSERT INTO names (FirstName, LastName, BirthDate) VALUES ('Yamila','Diaz ','1974-10-13');
Query OK, 1 row affected (0.00 sec)
Inserting multiple rows at a time:
7. mysql> INSERT INTO names (FirstName, LastName, BirthDate) VALUES ('Nikki','Taylor','1972-03-04'),
('Tia','Carrera','1975-09-18');
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
Let's see what the data looks like inside the table. We use the SELECT command for this.
mysql> SELECT * from NAMES;
+------------+-----------+----------+------------+
| contact_id | FirstName | LastName | BirthDate |
+------------+-----------+----------+------------+
| 3 | Tia | Carrera | 1975-09-18 |
| 2 | Nikki | Taylor | 1972-03-04 |
| 1 | Yamila | Diaz | 1974-10-13 |
+------------+-----------+----------+------------+
3 rows in set (0.06 sec)
Try another handy command called 'DESCRIBE'.
mysql> DESCRIBE names;
+------------+-------------+------+-----+---------+----------------+---------------------------------+
| Field | Type | Null | Key | Default | Extra | Privileges
|
+------------+-------------+------+-----+---------+----------------+---------------------------------+
| contact_id | smallint(6) | | PRI | NULL | auto_increment | select,insert,update,references |
| FirstName | char(20) | YES | | NULL | | select,insert,update,references |
| LastName | char(20) | YES | | NULL | | select,insert,update,references |
| BirthDate | date | YES | | NULL | | select,insert,update,references |
+------------+-------------+------+-----+---------+----------------+---------------------------------+
4 rows in set (0.00 sec)
Now lets populate the other tables. Observer the syntax used.
mysql> INSERT INTO address(contact_id, StreetAddress, City, State, Zip, Country) VALUES ('1', '300 Yamila Ave.', 'Los
Angeles', 'CA', '300012', 'USA'),('2','4000 Nikki St.','Boca Raton','FL','500034','USA'),('3','404 Tia Blvd.','New
York','NY','10011','USA');
Query OK, 3 rows affected (0.05 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM address;
+------------+-----------------+-------------+-------+--------+---------+
| contact_id | StreetAddress | City | State | Zip | Country |
+------------+-----------------+-------------+-------+--------+---------+
| 1 | 300 Yamila Ave. | Los Angeles | CA | 300012 | USA |
| 2 | 4000 Nikki St. | Boca Raton | FL | 500034 | USA |
| 3 | 404 Tia Blvd. | New York | NY | 10011 | USA |
+------------+-----------------+-------------+-------+--------+---------+
3 rows in set (0.00 sec)
mysql> INSERT INTO company_details (contact_id, CompanyName, Designation) VALUES ('1','Xerox','New Business
Manager'), ('2','Cabletron','Customer Support Eng'),('3','Apple','Sales Manager');
Query OK, 3 rows affected (0.05 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM company_details;
+------------+-------------+----------------------+
| contact_id | CompanyName | Designation |
+------------+-------------+----------------------+
| 1 | Xerox | New Business Manager |
| 2 | Cabletron | Customer Support Eng |
| 3 | Apple | Sales Manager |
+------------+-------------+----------------------+
3 rows in set (0.06 sec)
mysql> INSERT INTO email (contact_id, Email) VALUES ('1', 'yamila@yamila.com'),( '2', 'nikki@nikki.com'),('3','tia@tia.com');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM email;
+------------+-------------------+
| contact_id | Email |
+------------+-------------------+
| 1 | yamila@yamila.com |
| 2 | nikki@nikki.com |
| 3 | tia@tia.com |
+------------+-------------------+
3 rows in set (0.06 sec)
mysql> INSERT INTO telephones (contact_id, TelephoneHome, TelephoneWork) VALUES ('1','333-50000','333-60000'),
('2','444-70000','444-80000'),('3','555-30000','55 5-40000');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
8. mysql> SELECT * FROM telephones;
+------------+---------------+---------------+
| contact_id | TelephoneHome | TelephoneWork |
+------------+---------------+---------------+
| 1 | 333-50000 | 333-60000 |
| 2 | 444-70000 | 444-80000 |
| 3 | 555-30000 | 555-40000 |
+------------+---------------+---------------+
3 rows in set (0.00 sec)
Okay, so we now have all our data ready for experimentation.
Before we start experimenting with manipulating the data let's look at how MySQL
stores the Data.
To do this execute the following command from the shell prompt.
mysqldump contacts > contacts.sql
Note: The reverse operation for this command is:
mysql contacts < contacts.sql
The file generated is a text file that contains all the data and SQL instruction needed to recreate
the same database. As you can see, the SQL here is slightly different than what was typed in.
Don't worry about this. It's all good ! It would also be obvious that this is a good way to backup
your stuff.
# MySQL dump 8.2
#
# Host: localhost Database: contacts
#--------------------------------------------------------
# Server version 3.22.34-shareware-debug
#
# Table structure for table 'address'
#
CREATE TABLE address (
contact_id smallint(6) DEFAULT '0' NOT NULL,
StreetAddress char(50),
City char(20),
State char(20),
Zip char(10),
Country char(20),
PRIMARY KEY (contact_id)
);
#
# Dumping data for table 'address'
#
INSERT INTO address VALUES (1,'300 Yamila Ave.','Los Angeles','CA','300012','USA');
INSERT INTO address VALUES (2,'4000 Nikki St.','Boca Raton','FL','500034','USA');
INSERT INTO address VALUES (3,'404 Tia Blvd.','New York','NY','10011','USA');
#
# Table structure for table 'company_details'
#
CREATE TABLE company_details (
contact_id smallint(6) DEFAULT '0' NOT NULL,
CompanyName char(25),
Designation char(20),
PRIMARY KEY (contact_id)
);
#
# Dumping data for table 'company_details'
#
INSERT INTO company_details VALUES (1,'Xerox','New Business Manager');
INSERT INTO company_details VALUES (2,'Cabletron','Customer Support Eng');
INSERT INTO company_details VALUES (3,'Apple','Sales Manager');
#
# Table structure for table 'email'
9. #
CREATE TABLE email (
contact_id smallint(6) DEFAULT '0' NOT NULL,
Email char(20),
PRIMARY KEY (contact_id)
);
#
# Dumping data for table 'email'
#
INSERT INTO email VALUES (1,'yamila@yamila.com');
INSERT INTO email VALUES (2,'nikki@nikki.com');
INSERT INTO email VALUES (3,'tia@tia.com');
#
# Table structure for table 'names'
#
CREATE TABLE names (
contact_id smallint(6) DEFAULT '0' NOT NULL auto_increment,
FirstName char(20),
LastName char(20),
BirthDate date,
PRIMARY KEY (contact_id)
);
#
# Dumping data for table 'names'
#
INSERT INTO names VALUES (3,'Tia','Carrera','1975-09-18');
INSERT INTO names VALUES (2,'Nikki','Taylor','1972-03-04');
INSERT INTO names VALUES (1,'Yamila','Diaz','1974-10-13');
#
# Table structure for table 'telephones'
#
CREATE TABLE telephones (
contact_id smallint(6) DEFAULT '0' NOT NULL,
TelephoneHome char(20),
TelephoneWork char(20),
PRIMARY KEY (contact_id)
);
#
# Dumping data for table 'telephones'
#
INSERT INTO telephones VALUES (1,'333-50000','333-60000');
INSERT INTO telephones VALUES (2,'444-70000','444-80000');
INSERT INTO telephones VALUES (3,'555-30000','555-40000');
Let's try some SELECT statement variations:
To select all names whose corresponding contact_id is greater than 1.
mysql> SELECT * FROM names WHERE contact_id > 1;
+------------+-----------+----------+------------+
| contact_id | FirstName | LastName | BirthDate |
+------------+-----------+----------+------------+
| 3 | Tia | Carrera | 1975-09-18 |
| 2 | Nikki | Taylor | 1972-03-04 |
+------------+-----------+----------+------------+
2 rows in set (0.00 sec)
As a condition we can also use NOT NULL. This statement will return all names where there exists
a contact_id.
mysql> SELECT * FROM names WHERE contact_id IS NOT NULL;
+------------+-----------+----------+------------+
| contact_id | FirstName | LastName | BirthDate |
+------------+-----------+----------+------------+
| 3 | Tia | Carrera | 1975-09-18 |
| 2 | Nikki | Taylor | 1972-03-04 |
| 1 | Yamila | Diaz | 1974-10-13 |
+------------+-----------+----------+------------+
3 rows in set (0.06 sec)
10. Result's can be arranged in a particular way using the statement ORDER BY.
mysql> SELECT * FROM names WHERE contact_id IS NOT NULL ORDER BY LastName;
+------------+-----------+----------+------------+
| contact_id | FirstName | LastName | BirthDate |
+------------+-----------+----------+------------+
| 3 | Tia | Carrera | 1975-09-18 |
| 1 | Yamila | Diaz | 1974-10-13 |
| 2 | Nikki | Taylor | 1972-03-04 |
+------------+-----------+----------+------------+
3 rows in set (0.06 sec)
'asc' and 'desc' stand for ascending and descending respectively and can be used to arrange the
results.
mysql> SELECT * FROM names WHERE contact_id IS NOT NULL ORDER BY LastName desc;
+------------+-----------+----------+------------+
| contact_id | FirstName | LastName | BirthDate |
+------------+-----------+----------+------------+
| 2 | Nikki | Taylor | 1972-03-04 |
| 1 | Yamila | Diaz | 1974-10-13 |
| 3 | Tia | Carrera | 1975-09-18 |
+------------+-----------+----------+------------+
3 rows in set (0.04 sec)
You can also place date types into conditional statements.
mysql> SELECT * FROM names WHERE BirthDate > '1973-03-06';
+------------+-----------+----------+------------+
| contact_id | FirstName | LastName | BirthDate |
+------------+-----------+----------+------------+
| 3 | Tia | Carrera | 1975-09-18 |
| 1 | Yamila | Diaz | 1974-10-13 |
+------------+-----------+----------+------------+
2 rows in set (0.00 sec)
LIKE is a statement to match field values using wildcards. The % sign is used for denoting
wildcards and can represent multiple characters.
mysql> SELECT FirstName, LastName FROM names WHERE LastName LIKE 'C%';
+-----------+----------+
| FirstName | LastName |
+-----------+----------+
| Tia | Carrera |
+-----------+----------+
1 row in set (0.06 sec)
'_' is used to represent a single wildcard.
mysql> SELECT FirstName, LastName FROM names WHERE LastName LIKE '_iaz';
+-----------+----------+
| FirstName | LastName |
+-----------+----------+
| Yamila | Diaz |
+-----------+----------+
1 row in set (0.00 sec)
SQL Logical Operations (operates from Left to Right)
1.NOT or !
2. AND or &&
3. OR or ||
4. = : Equal
5. <> or != : Not Equal
6. <=
7. >=
8 <,>
Here are some more variations with Logical Operators and using the 'IN' statement.
11. mysql> SELECT FirstName FROM names WHERE contact_id < 3 AND LastName LIKE 'D%';
+-----------+
| FirstName |
+-----------+
| Yamila |
+-----------+
1 row in set (0.00 sec)
mysql> SELECT contact_id FROM names WHERE LastName IN ('Diaz','Carrera');
+------------+
| contact_id |
+------------+
|3|
|1|
+------------+
2 rows in set (0.02 sec)
To return the number of rows in a table
mysql> SELECT count(*) FROM names;
+----------+
| count(*) |
+----------+
|3|
+----------+
1 row in set (0.02 sec)
mysql> SELECT count(FirstName) FROM names;
+------------------+
| count(FirstName) |
+------------------+
|3|
+------------------+
1 row in set (0.00 sec)
To do some basic arithmetic aggregate functions.
mysql> SELECT SUM(contact_id) FROM names;
+-----------------+
| SUM(contact_id) |
+-----------------+
|6|
+-----------------+
1 row in set (0.00 sec)
To select a largest value from a row. Substitute 'MIN' and see what happens next.
mysql> SELECT MAX(contact_id) FROM names;
+-----------------+
| MAX(contact_id) |
+-----------------+
|3|
+-----------------+
1 row in set (0.00 sec)
HAVING
Take a look at the first query using the statement WHERE and the second statement using the
statement HAVING.
mysql> SELECT * FROM names WHERE contact_id >=1;
+------------+-----------+----------+------------+
| contact_id | FirstName | LastName | BirthDate |
+------------+-----------+----------+------------+
| 1 | Yamila | Diaz | 1974-10-13 |
| 2 | Nikki | Taylor | 1972-03-04 |
| 3 | Tia | Carrera | 1975-09-18 |
+------------+-----------+----------+------------+
3 rows in set (0.03 sec)
mysql> SELECT * FROM names HAVING contact_id >=1;
+------------+-----------+----------+------------+
| contact_id | FirstName | LastName | BirthDate |
+------------+-----------+----------+------------+
| 3 | Tia | Carrera | 1975-09-18 |
| 2 | Nikki | Taylor | 1972-03-04 |
| 1 | Yamila | Diaz | 1974-10-13 |
+------------+-----------+----------+------------+
3 rows in set (0.00 sec)
12. Now lets work with multiple tables and see how information can be pulled out of the data.
mysql> SELECT names.contact_id, FirstName, LastName, Email FROM names, email WHERE names.contact_id =
email.contact_id;
+------------+-----------+----------+-------------------+
| contact_id | FirstName | LastName | Email |
+------------+-----------+----------+-------------------+
| 1 | Yamila | Diaz | yamila@yamila.com |
| 2 | Nikki | Taylor | nikki@nikki.com |
| 3 | Tia | Carrera | tia@tia.com |
+------------+-----------+----------+-------------------+
3 rows in set (0.11 sec)
mysql> SELECT DISTINCT names.contact_id, FirstName, Email, TelephoneWork FROM names, email, telephones WHERE
names.contact_id=email.contact_id=telephones.contact_id;
+------------+-----------+-------------------+---------------+
| contact_id | FirstName | Email | TelephoneWork |
+------------+-----------+-------------------+---------------+
| 1 | Yamila | yamila@yamila.com | 333-60000 |
| 2 | Nikki | nikki@nikki.com | 333-60000 |
| 3 | Tia | tia@tia.com | 333-60000 |
+------------+-----------+-------------------+---------------+
3 rows in set (0.05 sec)
So what's a JOIN ?
JOIN is the action performed on multiple tables that returns a result as a table. It's
what makes a database 'relational'.
There are several types of joins. Let's look at LEFT JOIN (OUTER JOIN) and RIGHT JOIN
Let's first check out the contents of the tables we're going to use
mysql> SELECT * FROM names;
+------------+-----------+----------+------------+
| contact_id | FirstName | LastName | BirthDate |
+------------+-----------+----------+------------+
| 3 | Tia | Carrera | 1975-09-18 |
| 2 | Nikki | Taylor | 1972-03-04 |
| 1 | Yamila | Diaz | 1974-10-13 |
+------------+-----------+----------+------------+
3 rows in set (0.00 sec)
mysql> SELECT * FROM email;
+------------+-------------------+
| contact_id | Email |
+------------+-------------------+
| 1 | yamila@yamila.com |
| 2 | nikki@nikki.com |
| 3 | tia@tia.com |
+------------+-------------------+
3 rows in set (0.00 sec)
A LEFT JOIN First:
mysql> SELECT * FROM names LEFT JOIN email USING (contact_id);
+------------+-----------+----------+------------+------------+------------------+
| contact_id | FirstName | LastName | BirthDate | contact_id | Email|
+------------+-----------+----------+------------+------------+-------------------+
| 3 | Tia | Carrera | 1975-09-18 | 3 | tia@tia.com |
| 2 | Nikki | Taylor | 1972-03-04 | 2 | nikki@nikki.com |
| 1 | Yamila | Diaz | 1974-10-13 | 1 | yamila@yamila.com |
+------------+-----------+----------+------------+------------+-------------------+
3 rows in set (0.16 sec)
To find the people who have a home phone number.
mysql> SELECT names.FirstName FROM names LEFT JOIN telephones ON names.contact_id = telephones.contact_id WHERE
TelephoneHome IS NOT NULL;
+-----------+
| FirstName |
+-----------+
| Tia |
| Nikki |
| Yamila |
+-----------+
3 rows in set (0.02 sec)
13. These same query leaving out 'names' (from names.FirstName) is still the same and will generate the same result.
mysql> SELECT FirstName FROM names LEFT JOIN telephones ON names.contact_id = telephones.contact_id WHERE
TelephoneHome IS NOT NULL;
+-----------+
| FirstName |
+-----------+
| Tia |
| Nikki |
| Yamila |
+-----------+
3 rows in set (0.00 sec)
And now a RIGHT JOIN:
mysql> SELECT * FROM names RIGHT JOIN email USING(contact_id);
+------------+-----------+----------+------------+------------+----------------- --+
| contact_id | FirstName | LastName | BirthDate | contact_id | Email |
+------------+-----------+----------+------------+------------+-------------------+
| 1 | Yamila | Diaz | 1974-10-13 | 1 | yamila@yamila.com |
| 2 | Nikki | Taylor | 1972-03-04 | 2 | nikki@nikki.com
|
| 3 | Tia | Carrera | 1975-09-18 | 3 | tia@tia.com
|
+------------+-----------+----------+------------+------------+-----------------
--+
3 rows in set (0.03 sec)
BETWEEN
This conditional statement is used to select data where a certain related contraint falls between a
certain range of values. The following example illustrates it's use.
mysql> SELECT * FROM names;
+------------+-----------+----------+------------+
| contact_id | FirstName | LastName | BirthDate |
+------------+-----------+----------+------------+
| 3 | Tia | Carrera | 1975-09-18 |
| 2 | Nikki | Taylor | 1972-03-04 |
| 1 | Yamila | Diaz | 1974-10-13 |
+------------+-----------+----------+------------+
3 rows in set (0.06 sec)
mysql> SELECT FirstName, LastName FROM names WHERE contact_id BETWEEN 2 AND 3;
+-----------+----------+
| FirstName | LastName |
+-----------+----------+
| Tia | Carrera |
| Nikki | Taylor |
+-----------+----------+
2 rows in set (0.00 sec)
ALTER
The ALTER statement is used to add a new column to an existing table or to make changes to it.
mysql> ALTER TABLE names ADD Age SMALLINT;
Query OK, 3 rows affected (0.11 sec)
Records: 3 Duplicates: 0 Warnings: 0
Now let's take a look at the 'ALTER'ed Table.
mysql> SHOW COLUMNS FROM names;
+------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+----------------+
| contact_id | smallint(6) | | PRI | 0 | auto_increment |
| FirstName | char(20) | YES | | NULL | |
| LastName | char(20) | YES | | NULL | |
| BirthDate | date | YES | | NULL | |
| Age | smallint(6) | YES | | NULL | |
+------------+-------------+------+-----+---------+----------------+
5 rows in set (0.06 sec)
But we don't require Age to be a SMALLINT type when a TINYINT would suffice. So we use
14. another ALTER statement.
mysql> ALTER TABLE names CHANGE COLUMN Age Age TINYINT;
Query OK, 3 rows affected (0.02 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> SHOW COLUMNS FROM names;
+------------+-------------+------+-----+---------+--------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+--------+----------------+
| contact_id | smallint(6) | | PRI | NULL |
| FirstName | char(20) | YES | | NULL | |
| LastName | char(20) | YES | | NULL | |
| BirthDate | date | YES | | NULL | |
| Age | tinyint(4) | YES | | NULL | |
+------------+-------------+------+-----+---------+--------+----------------+
5 rows in set (0.00 sec)
MODIFY
You can also use the MODIFY statement to change column data types.
mysql> ALTER TABLE names MODIFY COLUMN Age SMALLINT;
Query OK, 3 rows affected (0.03 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> SHOW COLUMNS FROM names;
+------------+-------------+------+-----+---------+----------------+---------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+----------------+---------------+
| contact_id | smallint(6) | | PRI | NULL | auto_increment |
| FirstName | char(20) | YES | | NULL | |
| LastName | char(20) | YES | | NULL | |
| BirthDate | date | YES | | NULL | |
| Age | smallint(6) | YES | | NULL | |
+------------+-------------+------+-----+---------+----------------+---------------+
5 rows in set (0.00 sec)
To Rename a Table:
mysql> ALTER TABLE names RENAME AS mynames;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW TABLES;
+--------------------+
| Tables_in_contacts |
+--------------------+
| address |
| company_details |
| email |
| mynames |
| telephones |
+--------------------+
5 rows in set (0.00 sec)
We rename it back to the original name.
mysql> ALTER TABLE mynames RENAME AS names;
Query OK, 0 rows affected (0.01 sec)
UPDATE
The UPDATE command is used to add a value to a field in a table.
mysql> UPDATE names SET Age ='23' WHERE FirstName='Tia';
Query OK, 1 row affected (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 0
The Original Table:
mysql> SELECT * FROM names;
+------------+-----------+----------+------------+------+
| contact_id | FirstName | LastName | BirthDate | Age |
+------------+-----------+----------+------------+------+
| 3 | Tia | Carrera | 1975-09-18 | 23 |
| 2 | Nikki | Taylor | 1972-03-04 | NULL |
| 1 | Yamila | Diaz | 1974-10-13 | NULL |
+------------+-----------+----------+------------+------+
3 rows in set (0.05 sec)
15. The Modified Table:
mysql> SELECT * FROM names;
+------------+-----------+----------+------------+------+
| contact_id | FirstName | LastName | BirthDate | Age |
+------------+-----------+----------+------------+------+
| 3 | Tia | Carrera | 1975-09-18 | 24 |
| 2 | Nikki | Taylor | 1972-03-04 | NULL |
| 1 | Yamila | Diaz | 1974-10-13 | NULL |
+------------+-----------+----------+------------+------+
3 rows in set (0.00 sec)
DELETE
mysql> DELETE FROM names WHERE Age=23;
Query OK, 1 row affected (0.00 sec)
mysql> SELECT * FROM names;
+------------+-----------+----------+------------+------+
| contact_id | FirstName | LastName | BirthDate | Age |
+------------+-----------+----------+------------+------+
| 2 | Nikki | Taylor | 1972-03-04 | NULL |
| 1 | Yamila | Diaz | 1974-10-13 | NULL |
+------------+-----------+----------+------------+------+
2 rows in set (0.00 sec)
A DEADLY MISTAKE...
mysql> DELETE FROM names;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT * FROM names;
Empty set (0.00 sec)
One more destructive tool...
DROP TABLE
mysql> DROP TABLE names;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW TABLES;
+--------------------+
| Tables in contacts |
+--------------------+
| address |
| company_details |
| email |
| telephones |
+--------------------+
4 rows in set (0.05 sec)
mysql> DROP TABLE address ,company_details, telephones;
Query OK, 0 rows affected (0.06 sec)
mysql> SHOW TABLES;
Empty set (0.00 sec)
As you can see, the table 'names' no longer exists. MySQL does not give a warning so be careful.
FULL TEXT INDEXING and Searching
Since version 3.23.23, Full Text Indexing and Searching has been introduced into MySQL.
FULLTEXT indexes can be created from VARCHAR and TEXT columns. FULLTEXT searches are
performed with the MATCH function. The MATCH function matches a natural language query on a
text collection and from each row in a table it returns relevance.The resultant rows are organized
in order of relevance.
Full Text searches are a very powerful way to search through text. But is not ideal for small tables
of text and may produce inconsistent results. Ideally it works with large collections of textual
data.
16. Optimizing your Database
Well, databases do tend to get large at some or the other. And here arises the issue of database
optimization. Queries are going to take longer and longer as the database grows and certain
things can be done to speed things up.
Clustering
The easiest method is that of 'clustering'. Suppose you do a certain kind of query often, it would
be faster if the database contents were arranged in a in the same way data was requested. To
keep the tables in a sorted order you need a clustering index. Some databases keep stuff sorted
automatically.
Ordered Indices
These are a kind of 'lookup' tables of sorts. For each column that may be of interest to you, you
can create an ordered index.
It needs to be noted that again these kinds of optimization techniques produce a system load in
terms of creating a new index each time the data is re-arranged.
There are additional method such as B-Trees, Hashing which you may like to read up about but
will not be discussed here.
Replication
Replication is the term given to the process where databases synchronize with each other. In this
process one database updates it's own data with respect to another or with reference to certain
criteria for updates specified by the programmer. Replication can be used under various
circumstances. Examples may be : safety and backup, to provide a closer location to the database
for certain users.
What are Transactions ?
In an RDBMS, when several people access the same data or if a server dies in the middle of an
update, there has to be a mechanism to protect the integrity of the data. Such a mechanism is
called a Transaction. A transaction groups a set of database actions into a single instantaneous
event. This event can either succeed or fail. i.e .either get the job done or fail.
The definition of a transaction can be provided by an Acronym called 'ACID'.
(A)tomicity: If an action consists of multiple steps - it's still considered as one operation.
(C) Consistency: The database exists in a valid and accurate operating state before and after a
transaction.
(I) Isolation: Processes within one transaction are independent and cannot interfere with that in
others.
(D) Durability: Changes affected by a transaction are permanent.
To enable transactions a mechanism called 'Logging' needs to be introduced. Logging involves a
DBMS writing details on the tables, columns and results of a particular transaction, both before
and after, onto a log file. This log file is used in the process of recovery. Now to protect a certain
database resource (ex. a table) from being used and written onto simulatneously several
techniques are used. One of them is 'Locking' another is to put a 'time stamp' onto an action. In
the case of Locking, to complete an action, the DBMS would need to acquire locks on all resources
needed to complete the action. The locks are released only when the transaction is completed.
Now if there were say a large numbers of tables involved in a particular action, say 50, all 50
tables would be locked till a transaction is completed.
17. To improve things a bit, there is another technique used called 2 Phase Locking or 2PL. In this
method of locking, locks are acquired only when needed but are released only when the
transaction is completed.
This is done to make sure that that altered data can be safely restored if the transaction fails for
any reason.
This technique can also result in problems such as "deadlocks".
In this case - 2 processes requiring the same resources lock each other up by preventing the
other to complete an action. Options here are to abort one, or let the programmer handle it.
MySQL implements transactions by implementing the Berkeley DB libraries into its own code. So
it's the source version you'd want here for MySQL installation. Read the MySQL manual on
implementing this.
Beyond MySQL
What are Views ?
A view allows you to assign the result of a query to a new private table. This table is given the
name used in your VIEW query.
Although MySQL does not support views yet a sample SQL VIEW construct statement would look
like:
CREATE VIEW TESTVIEW AS SELECT * FROM names;
What are Triggers ?
A trigger is a pre-programmed notification that performs a set of actions that may be commonly
required. Triggers can be programmed to execute certain actions before or after an event occurs.
Triggers are very useful as they they increase efficiency and accuracy in performing operations on
databases and also are increase productivity by reducing the time for application development.
Triggers however do carry a price in terms of processing overhead.
What are Procedures ?
Like triggers, Procedures or 'Stored' Procedures are productivity enhancers. Suppose you needed
to perform an action using a programming interface to the database in say PERL and ASP. If a
programmed action could be stored at the database level, it's obvious that it has to be written
only once and cam be called by any programming language interacting with the database.
Procedures are executed using triggers.
Beyond RDBMS
Distributed Databases (DDB)
A distributed database is a collection of several, logically interrelated database located at multiple
locations of a computer network. A distributed database management system permits the
management of such a database and makes the operation transparent to the user. Good examples
of distributed databases would be those utilized by banks, multinational firms with several office
locations where each distributed data system works only with the data that is relevant to it's
18. operations. DDBs have have full functionality of any DBMS. It's also important to know that the
distributed databases are considered to be actually one database rather than discrete files and
data within distributed databases are logically interrelated.
Object Database Management Systems or ODBMS
When the capabilities of a database are integrated with object programming language
capababilities, the resulting product is an ODBMS. Database objects appear as
programming objects in an ODBMS. Using an ODBMS offers several advantages. The ones that
can be most readily appreciated are:
1. Efficiency
When you use an ODBMS, you're using data the way you store it. You will use less code as you're
not dependent on an intermediary like SQL or ODBC. When this happens you can create highly
complex data structures through your programming language.
2. Speed
When data is stored the way you'd like it to be stored (i.e. natively) there is a massive
performance increase as no to-and-fro translation is required.
A Quick Tutorial on Database Normalization
Let's start off by taking some data represented in a Table.
Table Name: College Table
StudentName CourseID1 CourseTitle1 CourseProfessor1 CourseID2 CourseTitle2 CourseProfessor2 StudentAdvisor StudentID
Object
Perl Regular Oriented
Tia Carrera CS123 Don Corleone CS003 Daffy Duck Fred Flintstone 400
Expressions Programming
1
Socket
John Wayne CS456 DJ Tiesto CS004 Algorithms Homer Simpson Barney Rubble 401
Programming
Data
Lara Croft CS789 OpenGL Bill Clinton CS001 Papa Smurf Seven of Nine 402
Structures
(text size has been shrunk to aid printability on one page)
The First Normal Form: (Each Column Type is Unique and there are no repeating groups
[types] of data)
This essentially means that you indentify data that can exist as a separate table and therefore
reduce repetition and will reduce the width of the original table.
We can see that for every student, Course Information is repeated for each course. So if a student
has three course, you'll need to add another set of columns for Course Title, Course Professor and
CourseID. So Student information and Course Information can be considered to be two broad
groups.
Table Name: Student
Information
StudentID (Primary Key)
StudentName
AdvisorName
Table Name: Course
Information
CourseID (Primary Key)
CourseTitle
19. CourseDescription
CourseProfessor
It's obvious that we have here a Many to Many relationship between Students and Courses.
Note: In a Many to Many relationship we need something called a relating table which basically
contains information exclusively on which relatioships exist between two tables. In a One to Many
relationship we use a foreign key.
So in this case we need another little table called: Students and Courses
Table Name: Students and
Courses
SnCStudentID
SnCCourseID
The Second Normal Form: (All attributes within the entity should depend solely on the
entity's unique identifier)
The AdvisorName under Student Information does not depend on the StudentID. Therefore it can
be moved to it's own table.
Table Name: Student
Information
StudentID (Primary Key)
StudentName
Table Name: Advisor
Information
AdvisorID
AdvisorName
Table Name: Course
Information
CourseID (Primary Key)
CourseTitle
CourseDescription
CourseProfessor
Table Name: Students and
Courses
SnCStudentID
SnCCourseID
Note: Relating Tables can be created as required.
The Third Normal Form:(no column entry should be dependent on any other entry
(value) other than the key for the table)
In simple terms - a table should contain information about only one thing.
In Course Information, we can pull CourseProfessor information out and store it in another table.
20. Table Name: Student
Information
StudentID (Primary Key)
StudentName
Table Name: Advisor
Information
AdvisorID
AdvisorName
Table Name: Course
Information
CourseID (Primary Key)
CourseTitle
CourseDescription
Table Name: Professor
Information
ProfessorID
CourseProfessor
Table Name: Students and
Courses
SnCStudentID
SnCCourseID
Note: Relating Tables can be created as required.
Well that's it. One you are done with 3NF the database is considered Normalized.
Now lets consider some cases where normalization would have to avoided for practical purposes.
Suppose we needed to store a students home address along with State and Zip Code information.
Would you create a separate table for every zipcode in your country along with one for cities and
one for states ? It actually depends on you. I would prefer just using a non-normalized address
table and stick everything in there. So exceptions crop up often and it's up to your better
judgement.