This document provides an overview and introduction to MySQL. It begins with a comparison of MySQL to Microsoft Access, noting MySQL's open source nature, cross-platform availability, and emphasis on fast query processing. Basic commands for connecting to a MySQL server and exploring database and table structures are presented. The document then covers SQL data definition and manipulation languages, including creating and modifying tables, inserting and selecting data. Joins between tables and use of aggregate functions are also summarized. Overall, the document provides a high-level tour of MySQL's basic features and capabilities.
This document is the user guide for Navicat 11. It begins with an overview of the software and its main features. It then discusses system requirements, registration, installation, maintenance, and the end user license agreement. The bulk of the document consists of detailed descriptions of the various database objects supported by Navicat for MySQL, Oracle, PostgreSQL, SQLite, and SQL Server. It explains the various tools and features in Navicat for working with these database objects and maintaining the databases.
This document is a module on modifying data and managing databases in SQL. It covers SQL statements for inserting, updating, and deleting data. It also discusses managing database structures like creating and modifying tables, creating views and indexes. The last part covers basic security concepts in SQL like granting and revoking user privileges.
This document provides instructions on installing and configuring MySQL on Linux. It discusses downloading and installing the MySQL RPM package, setting the root password for security, starting the MySQL server and client, and running basic queries to test the installation. It also covers additional MySQL commands and configurations including user privileges, database design, backups, and restoring data.
The document provides a tutorial on using SQL commands in MySQL. It begins with an overview of common commands like CREATE DATABASE, DROP DATABASE, CREATE TABLE, INSERT INTO. Sections then cover topics like relationships between tables, backups and indexing. The document includes examples to create a sample "southwind" database with a "products" table, insert rows, and run queries. It explains column definitions and provides the SQL needed to generate the tables and insert sample data.
This document provides information about partitioning in MySQL 5.1 presented by Sarah Sproehnle and Giuseppe Maxia. It discusses partitioning types (range, hash, list, key), partitioning expressions, partitioning pruning, benchmarking partitions, partitioning with different storage engines, partitioning by dates, and optimizing queries on partitioned tables.
SQL is a standard language for accessing and manipulating database systems. It allows users to define, manipulate, and query data within a relational database. Key statements in SQL include SELECT to query data, INSERT to add new rows, UPDATE to modify rows, and DELETE to remove rows. SQL also supports functions like DISTINCT, WHERE, ORDER BY, and JOIN to filter, sort, and combine data across tables respectively.
This document provides instructions and examples for using the MySQL database system. It discusses MySQL concepts like database, tables, rows, and columns. It also demonstrates common SQL commands like CREATE, SELECT, INSERT, UPDATE, DROP. Examples show how to create databases and tables, insert and query data, use functions, conditions and wildcards. Script files demonstrate populating tables with sample data.
This document provides an overview of basic SQL statements and SQL*Plus commands. It covers the capabilities of SELECT statements, including selecting all columns, specific columns, column aliases, arithmetic expressions, and literal strings. It also discusses null values, the concatenation operator, and eliminating duplicate rows with DISTINCT. Finally, it differentiates between SQL statements and SQL*Plus commands, describing how to log in to SQL*Plus, display table structure, edit SQL, and execute files of SQL statements.
This document discusses techniques for efficient pagination over large datasets using MySQL. The typical solution of using LIMIT and OFFSET can degrade performance as the offset increases. The document proposes using additional criteria like a "last seen" value combined with ordering to retrieve the next page without an offset. This allows fetching the next results set using an index scan. Testing showed a 6x improvement in query throughput over using large offsets. Additional enhancements like secondary indexes and caching are discussed to further optimize pagination.
SQL is a standard language for accessing and manipulating databases. It allows users to perform functions like querying data, inserting records, updating records, and deleting records. The main SQL statements are SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, and DROP. SQL also includes clauses like WHERE, ORDER BY, GROUP BY and JOIN that allow users to filter and sort query results. Common data definition language statements are used to create and modify database structures like tables, indexes, and relationships.
This document provides an overview of DB2 for OS/390 fundamentals, including a brief history of DB2, the internal workings and address spaces of DB2, SQL, DB2 objects, referential integrity, commands, utilities, and sample databases. It also covers topics like attachment facilities, data sharing, parallelism, SQL, authorities, indexes, and embedded SQL.
The document provides summaries of new features in MariaDB Server 10.2 and MariaDB MaxScale 2.1. For MariaDB Server 10.2, it introduces window functions, common table expressions, JSON and GeoJSON functions, improved replication features like delayed replication and compressed binary logs, and increased database compatibility. For MariaDB MaxScale 2.1, it does not provide any details.
This document provides an overview of basic SQL statements and SQL*Plus commands. It discusses SQL SELECT statements and their capabilities including selection, projection, and joins. It also demonstrates basic SELECT syntax and examples for selecting columns, arithmetic expressions, column aliases, concatenation, and literal strings. The document concludes with the differences between SQL statements and SQL*Plus commands and how to log in and describe tables using SQL*Plus.
This document provides an introduction to SQL (Structured Query Language) for manipulating and working with data. It covers SQL fundamentals including defining a database using DDL, working with views, writing queries, and establishing referential integrity. It also discusses SQL data types, database definition, creating tables and views, and key SQL statements for data manipulation including SELECT, INSERT, UPDATE, and DELETE. Examples are provided for creating tables and views, inserting, updating, and deleting data, and writing queries using functions, operators, sorting, grouping, and filtering.
SQL (Structured Query Language) is a standard language for accessing and manipulating databases. It allows users to execute queries against a database, retrieve data from a database, insert records into a database, update records in a database, and delete records from a database. Common SQL statements include SELECT to retrieve data, INSERT to add data, UPDATE to modify data, DELETE to remove data, and CREATE/ALTER to manage tables and databases.
MySQL is a relational database management system. It provides tools for managing data, including creating, querying, updating and deleting data in databases. Some key features include:
- Creating, altering and dropping databases, tables, indexes, users and more.
- Inserting, selecting, updating and deleting data with SQL statements.
- Backup and restore capabilities using mysqldump to backup entire databases or tables.
- Security features including user accounts and privileges to control access.
- Performance optimization using indexes, partitioning, query tuning and more.
- Data types for different kinds of data like numbers, dates, text, JSON and more.
SQL is a standard language for accessing and manipulating databases. The document provides an introduction to SQL basics including SQL statements to select, insert, update and delete data from database tables. It explains key SQL components like the WHERE clause for filtering records and the ORDER BY clause for sorting query results. Examples are given for each SQL statement and concept discussed.
The document describes the syntax for creating, altering, and dropping tables in SQL. It provides examples of creating tables with column constraints, default values, primary keys, foreign keys, and unique constraints. It also shows how to add, modify, and drop columns from existing tables using ALTER TABLE statements. The final sections cover DML statements for inserting, updating, deleting, and selecting data from tables.
This document summarizes new features in MariaDB Server 10.2, including:
- Window functions that improve efficiency of queries analyzing data by looking at "windows" of data.
- Common table expressions (CTEs) that allow defining temporary result sets to refer to in queries, making code more readable and efficient.
- JSON and GeoJSON functions for working with JSON-formatted data stored in MariaDB and converting between geometry and GeoJSON formats.
- New replication features like delayed replication and compressed binary logs that reduce load on masters and network usage.
- Increased database compatibility through features like multiple triggers per table, CHECK constraints for data validation, and improved expressions.
- A table is a logical representation of data stored in a database. It holds data in rows and columns.
- Data Definition Language (DDL) commands like CREATE, ALTER, TRUNCATE, DROP are used to create, modify and delete database objects like tables.
- Data Manipulation Language (DML) commands like INSERT, SELECT, UPDATE, DELETE are used to query and manipulate data in existing tables.
This document discusses using SQL in FileMaker. It provides an overview of executing SQL statements using ExecuteSQL() and a plug-in called DoSQL 2. It covers the main SQL commands supported like SELECT, INSERT, UPDATE, DELETE. It also discusses topics like parameters, results, errors, logging and debugging. Common mistakes when using SQL are also outlined.
This document discusses various SQL concepts including data types, data definition language (DDL), data manipulation language (DML), constraints, and transactions. It provides examples of creating tables with different data types, inserting, updating, and deleting data, setting constraints, and using transactions like commit and rollback. Key points covered include creating a table with a timestamp column, using case expressions, cursor for loops, and nested procedures and exception handling.
The document provides an introduction to SQL and covers various SQL statements and operators including:
1. SQL statements like SELECT, INSERT, UPDATE, and DELETE are used to retrieve, modify and manipulate data in databases.
2. Operators like WHERE, BETWEEN, IN, LIKE and NULL are used to filter rows and compare values in conditions.
3. Functions and clauses such as SELECT, FROM, DISTINCT, GROUP BY, JOIN, ORDER BY, etc. are used to customize data retrieval and presentation.
This document provides an overview and instructions for installing and using the MySQL database system. It describes MySQL's client-server architecture, how to connect to the MySQL server using the command line client, and provides examples of common SQL commands for creating databases and tables, inserting, selecting, updating, and deleting rows of data. It also introduces some basic SQL functions and provides SQL scripts as examples to create tables and insert data.
The document discusses Structured Query Language (SQL) and its basic statements. It covers:
- SQL is used to request and retrieve data from databases. The DBMS processes SQL queries and returns results.
- SQL statements are divided into DDL (data definition language) for managing schema, DML (data manipulation language) for data queries/modification, and DCL (data control language) for managing transactions and access control.
- The document provides examples of using SQL commands like CREATE TABLE, ALTER TABLE, DROP TABLE, INSERT, UPDATE, DELETE, SELECT and indexes. It also covers data types, constraints and operators used in SQL queries.
This document provides an introduction to Microsoft SQL Server and basic SQL statements. It discusses that MS SQL Server is a relational database management system developed by Microsoft that stores and retrieves data. It has several editions for different workloads and audiences. It then covers key SQL statements like CREATE TABLE, SELECT, INSERT, UPDATE, and DELETE and provides examples of how to use each statement to interact with database tables in MS SQL Server.
This document discusses techniques for efficient pagination over large datasets using MySQL. The typical solution of using LIMIT and OFFSET can degrade performance as the offset increases. The document proposes using additional criteria like a "last seen" value combined with ordering to retrieve the next page without an offset. This allows fetching the next results set using an index scan. Testing showed a 6x improvement in query throughput over using large offsets. Additional enhancements like secondary indexes and caching are discussed to further optimize pagination.
SQL is a standard language for accessing and manipulating databases. It allows users to perform functions like querying data, inserting records, updating records, and deleting records. The main SQL statements are SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, and DROP. SQL also includes clauses like WHERE, ORDER BY, GROUP BY and JOIN that allow users to filter and sort query results. Common data definition language statements are used to create and modify database structures like tables, indexes, and relationships.
This document provides an overview of DB2 for OS/390 fundamentals, including a brief history of DB2, the internal workings and address spaces of DB2, SQL, DB2 objects, referential integrity, commands, utilities, and sample databases. It also covers topics like attachment facilities, data sharing, parallelism, SQL, authorities, indexes, and embedded SQL.
The document provides summaries of new features in MariaDB Server 10.2 and MariaDB MaxScale 2.1. For MariaDB Server 10.2, it introduces window functions, common table expressions, JSON and GeoJSON functions, improved replication features like delayed replication and compressed binary logs, and increased database compatibility. For MariaDB MaxScale 2.1, it does not provide any details.
This document provides an overview of basic SQL statements and SQL*Plus commands. It discusses SQL SELECT statements and their capabilities including selection, projection, and joins. It also demonstrates basic SELECT syntax and examples for selecting columns, arithmetic expressions, column aliases, concatenation, and literal strings. The document concludes with the differences between SQL statements and SQL*Plus commands and how to log in and describe tables using SQL*Plus.
This document provides an introduction to SQL (Structured Query Language) for manipulating and working with data. It covers SQL fundamentals including defining a database using DDL, working with views, writing queries, and establishing referential integrity. It also discusses SQL data types, database definition, creating tables and views, and key SQL statements for data manipulation including SELECT, INSERT, UPDATE, and DELETE. Examples are provided for creating tables and views, inserting, updating, and deleting data, and writing queries using functions, operators, sorting, grouping, and filtering.
SQL (Structured Query Language) is a standard language for accessing and manipulating databases. It allows users to execute queries against a database, retrieve data from a database, insert records into a database, update records in a database, and delete records from a database. Common SQL statements include SELECT to retrieve data, INSERT to add data, UPDATE to modify data, DELETE to remove data, and CREATE/ALTER to manage tables and databases.
MySQL is a relational database management system. It provides tools for managing data, including creating, querying, updating and deleting data in databases. Some key features include:
- Creating, altering and dropping databases, tables, indexes, users and more.
- Inserting, selecting, updating and deleting data with SQL statements.
- Backup and restore capabilities using mysqldump to backup entire databases or tables.
- Security features including user accounts and privileges to control access.
- Performance optimization using indexes, partitioning, query tuning and more.
- Data types for different kinds of data like numbers, dates, text, JSON and more.
SQL is a standard language for accessing and manipulating databases. The document provides an introduction to SQL basics including SQL statements to select, insert, update and delete data from database tables. It explains key SQL components like the WHERE clause for filtering records and the ORDER BY clause for sorting query results. Examples are given for each SQL statement and concept discussed.
The document describes the syntax for creating, altering, and dropping tables in SQL. It provides examples of creating tables with column constraints, default values, primary keys, foreign keys, and unique constraints. It also shows how to add, modify, and drop columns from existing tables using ALTER TABLE statements. The final sections cover DML statements for inserting, updating, deleting, and selecting data from tables.
This document summarizes new features in MariaDB Server 10.2, including:
- Window functions that improve efficiency of queries analyzing data by looking at "windows" of data.
- Common table expressions (CTEs) that allow defining temporary result sets to refer to in queries, making code more readable and efficient.
- JSON and GeoJSON functions for working with JSON-formatted data stored in MariaDB and converting between geometry and GeoJSON formats.
- New replication features like delayed replication and compressed binary logs that reduce load on masters and network usage.
- Increased database compatibility through features like multiple triggers per table, CHECK constraints for data validation, and improved expressions.
- A table is a logical representation of data stored in a database. It holds data in rows and columns.
- Data Definition Language (DDL) commands like CREATE, ALTER, TRUNCATE, DROP are used to create, modify and delete database objects like tables.
- Data Manipulation Language (DML) commands like INSERT, SELECT, UPDATE, DELETE are used to query and manipulate data in existing tables.
This document discusses using SQL in FileMaker. It provides an overview of executing SQL statements using ExecuteSQL() and a plug-in called DoSQL 2. It covers the main SQL commands supported like SELECT, INSERT, UPDATE, DELETE. It also discusses topics like parameters, results, errors, logging and debugging. Common mistakes when using SQL are also outlined.
This document discusses various SQL concepts including data types, data definition language (DDL), data manipulation language (DML), constraints, and transactions. It provides examples of creating tables with different data types, inserting, updating, and deleting data, setting constraints, and using transactions like commit and rollback. Key points covered include creating a table with a timestamp column, using case expressions, cursor for loops, and nested procedures and exception handling.
The document provides an introduction to SQL and covers various SQL statements and operators including:
1. SQL statements like SELECT, INSERT, UPDATE, and DELETE are used to retrieve, modify and manipulate data in databases.
2. Operators like WHERE, BETWEEN, IN, LIKE and NULL are used to filter rows and compare values in conditions.
3. Functions and clauses such as SELECT, FROM, DISTINCT, GROUP BY, JOIN, ORDER BY, etc. are used to customize data retrieval and presentation.
This document provides an overview and instructions for installing and using the MySQL database system. It describes MySQL's client-server architecture, how to connect to the MySQL server using the command line client, and provides examples of common SQL commands for creating databases and tables, inserting, selecting, updating, and deleting rows of data. It also introduces some basic SQL functions and provides SQL scripts as examples to create tables and insert data.
The document discusses Structured Query Language (SQL) and its basic statements. It covers:
- SQL is used to request and retrieve data from databases. The DBMS processes SQL queries and returns results.
- SQL statements are divided into DDL (data definition language) for managing schema, DML (data manipulation language) for data queries/modification, and DCL (data control language) for managing transactions and access control.
- The document provides examples of using SQL commands like CREATE TABLE, ALTER TABLE, DROP TABLE, INSERT, UPDATE, DELETE, SELECT and indexes. It also covers data types, constraints and operators used in SQL queries.
This document provides an introduction to Microsoft SQL Server and basic SQL statements. It discusses that MS SQL Server is a relational database management system developed by Microsoft that stores and retrieves data. It has several editions for different workloads and audiences. It then covers key SQL statements like CREATE TABLE, SELECT, INSERT, UPDATE, and DELETE and provides examples of how to use each statement to interact with database tables in MS SQL Server.
The document discusses new developer features introduced in SQL Server 2012-2016, including SSDT tools, T-SQL improvements like THROW and sequences, in-memory OLTP, common table expressions, and features in SQL Server 2016 such as dynamic data masking, row-level security, always encrypted, temporal tables, and JSON support. SQL Server 2016 also introduced the DROP IF EXISTS statement to drop objects and the ability to insert rows using merge statements with common table expressions.
The document provides steps for installing MySQL on Windows, describes basic SQL commands like CREATE, SELECT, INSERT, UPDATE and DELETE. It also covers how to create databases and tables, grant user privileges, and includes examples of various SQL statements.
Designer's Favorite New Features in SQLServerKaren Lopez
油
A database designer's favourte features in SQL Server...with a bit of Azure SQL DB, too.
Always Encrypted
Row Level Security
Microsoft Purview
Azure Enabled SQL Server
Azure Defender for SQL
Azure Defender for Cloud
Dynamic Data Masking
Ledger Database and Tables
Data Privacy
Data Governance
This document provides information about SQL and database management systems. It discusses:
- SQL is a standard language for querying, manipulating, and defining data in databases. It was developed by IBM in the 1970s.
- SQL can be used to perform functions like retrieving data from a database, inserting new records, updating existing records, and deleting records.
- The main components of SQL are DDL, DML, DCL, and DQL which allow creating, modifying and deleting database structures, manipulating data, controlling access to data, and querying data respectively.
- Common SQL statements are discussed including SELECT, INSERT, UPDATE, DELETE, ALTER, CREATE TABLE, and DROP TABLE. Data types and
The document provides an overview of SQL commands and operations including:
1) Creating a database and table, inserting and selecting data, updating records with WHERE clauses.
2) Altering tables by adding or modifying columns and constraints.
3) Different SQL statements like SELECT, INSERT, UPDATE and DELETE and clauses like WHERE are discussed along with syntax and examples.
This document provides instructions and examples for using the MySQL database system. It discusses MySQL concepts like database, tables, rows, and columns. It also demonstrates common SQL commands like CREATE, SELECT, INSERT, UPDATE, DROP. Examples show how to create databases and tables, insert data, query data, and more. Installation and configuration steps are also covered.
A Designer's Favourite Security and Privacy Features in SQL Server and Azure ...Karen Lopez
油
SQL Server includes multiple features that focus on data security, privacy, and developer productivity. In this session, we will review the best features from a database designers and developers point of view.
Always Encrypted
Dynamic Data Masking
Row Level Security
Data Classification
Assessments
Defender for SQL Server
Ledger Tables
and more
Well look at new and older features, why you should consider them, where they work, where they dont, who needs to be involved in using them, and what changes, if any, need to be made to applications or tools that you use with SQL Server.
You will learn:
The pros and cons of implementing each feature
How implementing these new features may impact existing applications
10 tips for enhancing SQL Server security and privacy protections
SQL DDL: tricks and tips (JProf#27, Minsk, 24th September)Mikalai Sitsko
油
This document summarizes an SQL DDL presentation covering IDs, domains, calculated columns, constraints, and triggers. It discusses various techniques for each topic, such as using sequences or auto-increment for IDs, domains for standardizing data types, views or generated columns for calculations, primary keys, foreign keys, unique constraints and checks for data integrity rules, and DML, DDL, and database triggers for logging and validation. The presentation provides pros and cons of each approach and concludes that thinking low-level and writing high-level code are important principles for working with SQL DDL.
SQL Server is a relational database management system developed by Microsoft. It supports the SQL language and Microsoft's proprietary T-SQL language. Microsoft and Sybase originally released SQL Server 1.0 in 1989. Key editions include Enterprise, Standard, Web, Developer, and Express. Running multiple SQL Server instances on the same machine provides advantages like installation of different versions, maintenance of separate environments, and reducing temporary database problems. The document discusses how to create, alter, drop, backup, and restore SQL Server databases and tables. It also covers SQL Server data types and how to perform data manipulation operations like insert, update, and delete. Additionally, it explains how to define primary keys, foreign keys, unique constraints, check constraints, and
The Ring programming language version 1.10 book - Part 36 of 212Mahmoud Samir Fayed
油
This document provides documentation on ODBC functions in the Ring programming language. It describes functions for initializing an ODBC connection, getting driver and data source lists, connecting to and disconnecting from databases, executing queries, fetching results, and managing transactions. Examples are given showing how to use the functions to print ODBC information, execute queries, and commit or rollback transactions. The functions provided allow for full functionality in connecting Ring programs to databases using ODBC.
This document provides information and resources for the Cassandra certification workshop, including:
- Details on the Administrator and Developer certifications and required resources
- A 6-step process for obtaining certification, including completing courses on the DataStax Academy platform and scheduling an exam
- Practice questions covering Cassandra query language (CQL) concepts tested in the certification exams
- A demonstration of the certification process
SQL Server is a relational database management system developed by Microsoft that supports the SQL language. It has various editions like Enterprise, Standard, and Web. SQL Server allows running multiple instances of the same version on a single machine for benefits like installation of different versions, maintenance of environments, and reducing temporary problems. Key features include creating, altering, and dropping databases and tables. Data can be manipulated using insert, update, and delete commands. Primary keys, foreign keys, unique constraints, and indexes can be defined to enforce data integrity and improve query performance.
This document discusses Java input and output (I/O). It covers I/O fundamentals including streams, files, and text vs binary I/O. It describes the File class for working with file paths and attributes. It also outlines the Reader, Writer, InputStream and OutputStream classes and their methods for reading and writing text and binary data to and from files and streams.
This document provides an overview of input and output streams in Java. It discusses the java.io package and interfaces for reading from and writing to various sources like the keyboard, files, and other programs. It explains how to use classes like BufferedReader and Scanner to read input from the keyboard or a file. It also covers concepts like byte streams, character streams, buffered streams, and detecting end of stream conditions. The document is intended as a beginner's guide for using input/output in Java and compares the approaches using java.io versus alternatives like Scanner from java.util.
The document discusses Java input and output (I/O) fundamentals. It explains that all I/O in Java is performed by writing to and reading from streams of data. It also discusses the differences between text I/O using Reader/Writer classes and binary I/O using InputStream/OutputStream classes. The File class represents file and directory paths and provides methods for file manipulation and attribute checking.
MySQL is an SQL-based database management system that is compatible with standard SQL. It can be downloaded from the MySQL website. The document provides information on accessing MySQL, describes databases and tables, gives SQL commands and examples using a banking database, and covers topics like queries, joins, views, and modifying databases.
This document provides an overview and introduction to MySQL. It begins with a comparison of MySQL to Microsoft Access, noting MySQL's open source nature, availability on multiple platforms, and emphasis on fast query processing. It then covers how to connect to the MySQL server from the command line. The document spends the majority of its time reviewing SQL, including data definition commands to create tables and define data types, as well as data manipulation commands to select, insert, update and delete data. It also covers joining multiple tables, ordering and grouping results, and using aggregate functions. In summary, this document serves as an introduction and primer to the basics of MySQL and SQL.
The document discusses input and output in Java using the java.io package. It provides examples of reading keyboard input using BufferedReader and reading file input using FileReader. It also provides examples of writing console output using System.out and writing to files using PrintWriter. The document explains that java.io streams provide independence from the source or destination of the input/output.
MySQL is an SQL-based database management system that is compatible with standard SQL. It can be downloaded from the MySQL website. The document provides information on accessing MySQL, entering and editing commands, retrieving information about databases and tables, examples using a banking database, SQL queries, modifications to databases, and more. Resources for SQL scripts to create sample databases and tables are also included.
MySQL is an SQL-based database management system that is commonly used with PHP and Perl. It allows users to create, access, and modify databases and their tables. The document provides information on downloading and accessing MySQL, describes basic SQL commands like SELECT and CREATE DATABASE, and provides examples of queries, joins, and modifying databases using MySQL.
2. Contents
What is MySQL?
Comparison with Access
Running MySQL in the labs
SQL
Data Definition language
Creating tables
Data types
Data manipulation language
Select, Insert,
This is mostly revision of CM2020
3. MySQL
A popular OpenSource SQL Database
management system
> 10 million installations
Developed and supported by MySQL AB
www.mysql.com
Emphasis on fast query processing
Early versions lacked essential features
Views, procedural code, support for relational
integrity
These are all present in version 5.0 onwards
4. Comparison with Access
MySQL
Access
GUI: QBE, Simple table
creation, drag & drop
forms,
Windows only
Command line interface
Non-standard SQL
ANSI SQL
Not particularly fast
Fast
Available on Windows,
Linux, Macintosh
11. Data Types
See chapter 10 of the manual for more details on data types
Strings
CHAR(N), VARCHAR(N)
CHARs are padded to length N
VARCHARs are variable length N
BLOB
Large binary files, e.g. images
TEXT(N)
TINYTEXT TEXT MEDIUMTEXT LONGTEXT
Long text strings, e.g. text typed by user into box
12. Data Types
Another String type: Enum
CREATE TABLE Driver (
Title
ENUM (Mr, Mrs, Ms),
DriverID
CHAR(6),
Name
VARCHAR(20),
Points
INT
);
13. Data Types
DATE, DATETIME
CREATE TABLE Driver (
Title
ENUM (Mr, Mrs, Ms),
DriverID
CHAR(6),
DateOfBirth
DATE, -- YYYY-MM-DD, e.g. 1959-07-04
Name
VARCHAR(20),
);
CREATE TABLE Order (
OrderID
CHAR(8),
ProductID
CHAR(8)
Number
INT
Date
DATETIME -- YYYY-MM-DD HH-MM-SS
-- e.g. 2007-09-30 09-30-15
);
14. Data Types
Numeric
INT
Integers
FLOAT, DOUBLE
Floating point numbers
N.B. These are approximate values
DECIMAL(P, S) # Precision, Scale
Exact values
Example:
Suppose cost 5000, e.g., cost = 3289.75
Appropriate data-type for cost is:
cost DECIMAL(6, 2)
15. Constraints
Table definitions can include Constraints
Constraints implement Data Integrity
Recall:
Data Integrity ensures data is correct
16. Column Constraints
Primary keys can be implemented as column
constraints
CREATE TABLE Driver (
Title
ENUM (Mr, Mrs, Ms),
DriverID
CHAR(6) PRIMARY KEY,
Name
VARCHAR(20)
);
MySQL implements primary key integrity
17. Table constraints
CREATE TABLE Driver (
Title
ENUM (Mr, Mrs, Ms),
DriverID
CHAR(6),
CONSTRAINT pkdriv PRIMARY KEY DriverID);
CREATE TABLE Grades (
StudentID
CHAR(10),
ModuleID
CHAR(7),
Grade
CHAR(1),
CONSTRAINT pkgrade PRIMARY KEY (StudentID, ModuleID)
);
A composite primary key must be declared as a table
constraint, not as part of a column definition.
19. Declaring Foreign Keys
CREATE TABLE Department (
Deptcode
CHAR(4),
Deptname
VARCHAR(20),
CONSTRAINT dep_con1 PRIMARY KEY (Deptcode)
);
CREATE TABLE Staff (
Staffcode
StaffName
Dept
);
Optional, if its the primary key
CHAR(4),
VARCHAR(20),
CHAR(4) REFERENCES Department(Deptcode)
CREATE TABLE Staff2 (-- An alternative way of declaring a FK
Staffcode
CHAR(4),
StaffName
VARCHAR(20),
Dept
CHAR(4),
FOREIGN KEY (Dept) REFERENCES Department
);
Can be multiple valued, to match composite
primary key
21. Integrity constraints in MySQL
MySQL 5.0 implements primary key integrity and
referential integrity on foreign keys.
MySQL 5.0 doesnt implement any other forms of
integrity checking
CREATE TABLE Driver (
Title
DriverID
Name
Points
);
ENUM (Mr, Mrs, Ms),
CHAR(6) PRIMARY KEY,
VARCHAR(20),
INT check (Points < 8)
This will be
ignored
22. Properties of FK links
Staff
StaffCode
S1
S2
S3
StaffName
Fred
Bill
Jim
Dept*
D1
D1
D2
Department
DCode
D1
D2
D3
DName
Art
Computing
Business
What happens to the Staff table
if the Art department is closed,
or changes its DCode?
23. Link Properties: On Delete, On Update
Staff
SID
S1
S2
Name DID*
D1
Fred D1
D2
NULL
Bill
Link properties
S3
On Jim
delete: Cascade
On delete: Set Null
On delete: Set Default
Dept
DID
D1
Name
Art
D2
Computing
24. Link Properties: On Delete, On Update
Staff
SID
S1
S2
Name DID*
D1
D42
Fred D42
D1
D2
NULL
Bill
Link properties
S3
Jim
On update: Cascade
On update: Set Null
On delete: Set Default
Dept
DID
Name
D1
Art
D42
D0x79fc D2
Computing
25. Setting link properties in SQL
CREATE TABLE Department (
Deptcode
CHAR(4),
Deptname
VARCHAR(20),
CONSTRAINT dep_con1 PRIMARY KEY (Deptcode)
);
CREATE TABLE Staff (
Staffcode
StaffName
Dept
);
CHAR(4),
VARCHAR(20),
CHAR(4)
FOREIGN KEY (Dept) REFERENCES Department
ON DELETE SET NULL
ON UPDATE SET NULL
27. The Select Command
Marks
Name
Absolom
Bloggs
Carver
Donald
SELECT <field list>
FROM <table list>
WHERE <condition>;
RDB
Java
45
50
55
46
80
67
56
50
Pick columns
Pick tables
Pick rows
Business Intranet
87
90
91
89
60
62
63
67
SELECT *
FROM Marks
WHERE Name = Bloggs OR Name = Donald
Bloggs
Donald
50
46
67
50
90
89
62
67
27
28. The Select Command
Marks
Name
Absolom
Bloggs
Carver
Donald
SELECT <field list>
FROM <table list>
WHERE <condition>;
RDB
Java
45
50
55
46
80
67
56
50
Pick columns
Pick tables
Pick rows
Business Intranet
87
90
91
89
60
62
63
67
SELECT Name, Java
FROM Marks;
Absolom
Bloggs
Carver
Donald
80
67
56
50
28
29. The Select Command
SELECT <field list>
FROM <table list>
WHERE <condition>;
Marks
Name
Absolom
Bloggs
Carver
Donald
RDB
Java
45
50
55
46
80
67
56
50
Pick columns
Pick tables
Pick rows
Business Intranet
87
90
91
89
60
62
63
67
SELECT Name, Java
FROM Marks
WHERE Name = Carver;
Carver
56
29
30. Regular Expressions Pattern Matching
Use the operators LIKE or REGEXP in the WHERE field of SELECT
LIKE is standard SQL (See manual section 3.3.4.7)
REGEXP is an extra feature provided by My SQL (11.4.1)
LIKE
% represents any number of characters
_ represents exactly one character
SELECT *
FROM Driver
WHERE PostCode like AB%
selects drivers whose post-code starts AB
31. Inserting, Modifying and
Deleting Data
Insert Load a record at a time
Load Import a table from a file
Update Change the value of a field
Delete - Delete one or more records
32. INSERT
CREATE TABLE Driver (
Title
ENUM (Mr, Mrs, Ms),
DriverID
CHAR(6) PRIMARY KEY,
Name
VARCHAR(20)
);
INSERT INTO DRIVER VALUES
-- A complete row
(Mr, D00123, Smith);
INSERT INTO DRIVER (DriverID, Name) VALUES
-- Specified values
(D00124, Jones);
33. LOAD
Load is similar to the import table feature in Access
See section 12.2.5 for more details
CREATE TABLE Driver (
DriverID
CHAR(6) PRIMARY KEY,
Title
ENUM (Mr, Mrs, Ms),
Name
VARCHAR(20)
);
File stored on
client
LOAD DATA LOCAL INFILE driver.txt -- Tab-separated fields
INTO TABLE Driver ;
D00001
D00002
D00003
D00004
Mr
Mrs
Mr
Ms
Boggis
Boggis
Ernie
Tracy
37. Cartesian Product in SQL
Main
Pudding
MC1 Roast Beef
MC2 Roast Lamb
MC3 Chicken Tikka
SELECT *
FROM Main, Pudding;
MC1
MC1
MC1
MC2
MC3
MC3
P1 Ice Cream
P2 Apple Crumble
Roast Beef
Roast Beef
Roast Lamb
Roast Lamb
Chicken Tikka
Chicken Tikka
P1
P2
P1
P2
P1
P2
Ice Cream
Apple Crumble
Ice Cream
Apple Crumble
Ice Cream
Apple Crumble
38
38. Inner Join in My SQL
Staff
ID s_name Prj#*
S1
Jones P1
S2
Carey P1
S3
Fuller P2
S4
Mack P2
Proj
ID
P1
P2
P3
p_name
Aramis
Athena
Oracle
These two statements are equivalent
SELECT *
FROM Staff, Proj
WHERE Staff.Prj# = Proj.ID;
SELECT *
FROM Staff INNER JOIN Proj
ON Staff.Prj# = Proj.ID;
Staff.ID s_name Staff.Prj# Proj.ID
S1
Jones
P1
P1
S2
Carey P1
P1
S3
Fuller P2
P2
S4
Mack
P2
P2
p_name
Aramis
Aramis
Athena
Athena
39
39. Natural Join in SQL
Staff
ID s_name Prj#*
S1
Jones P1
S2
Carey P1
S3
Fuller P2
S4
Mack P2
Proj
ID
P1
P2
P3
p_name
Aramis
Athena
Oracle
SELECT Staff.ID, s_name, Staff.Prj#, p_name
FROM Staff, Proj
WHERE Staff.Prj# = Proj.ID
Staff.ID s_name
S1
Jones
S2
Carey
S3
Fuller
S4
Mack
Staff.Prj#
P1
P1
P2
P2
p_name
Aramis
Aramis
Athena
Athena
40
40. Outer Joins
Proj
Staff
ID s_name Prj#*
S1
Jones P1
S2
Carey P1
S3
Fuller P2
S4
Mack P2
ID
P1
P2
P3
p_name
Aramis
Athena
Oracle
Inner and Natural joins return only those
rows which match on a given field
Outer Join also returns rows from one table which have no match in the other
table;
SELECT *
FROM Staff RIGHT JOIN Proj ON Staff.Prj# = Proj.ID;
Staff.ID s_name Staff.Prj# Proj.ID
S1
Jones
P1
P1
S2
Carey P1
P1
S3
Fuller P2
P2
S4
Mack
P2
P2
NULL
NULL
NULL
P3
p_name
Aramis
Aramis
Athena
Athena
41 Oracle
45. Grouping
Loan# Book#
L0002 B0001
Memno
M0001
L0003 B0002
M0001
L0004 B0003
L0006 B0004
L0008 B0000
M0001
M0002
M0002
How many loans does
each member have?
SELECT memno, COUNT(*) AS num_loans
FROM Loan;
Memno num_loans
M0001
5
M0001
5
M0001
5
M0002
5
M0002
5
46
46. Grouping
Loan# Book#
L0002 B0001
Memno
M0001
L0003 B0002
M0001
L0004 B0003
L0006 B0004
L0008 B0000
M0001
M0002
M0002
How many loans does
each member have?
SELECT memno, COUNT(*) AS num_loans
FROM BY memno;
GROUP Loan
Memno num_loans
M0001 3
M0002 2
One entry in results table for each different value of
memno
47
Aggregates are evaluated separately for each group
48. SQL Summary
Data definition language
Creating tables
Setting data types
Defining constraints
Data manipulation language
Reading, writing and updating records in
tables
For more details, see the MySQL manual