The document discusses relational database management systems and the SQL language. It provides information on some key concepts:
1. Tables are the fundamental data structure in relational databases, organized as rows and columns. Each table has a unique name and columns must have unique names within the table.
2. SQL is the standard language used to communicate with relational databases to organize, manage and retrieve data. Key SQL commands include SELECT, INSERT, UPDATE, DELETE.
3. ALTER TABLE, CREATE TABLE, DROP TABLE, and other commands are used to define and modify database structure. Data types supported include numeric, date, text. Columns can be added, modified, or dropped from tables.
Consists of the explanations of the basics of SQL and commands of SQL.Helpful for II PU NCERT students and also degree studeents to understand some basic things.
Consists of the explanations of the basics of SQL and commands of SQL.Helpful for II PU NCERT students and also degree studeents to understand some basic things.
Presented by,
Mr. Abhilash K
Database Architect, Livares Technologies
Introduction
About DBMS
A database management system (DBMS) is a software for
creating and managing databases. DBMS provides
users/programmers with a systematic way to create,
retrieve, update and manage data.
What is RDBMS
A type of DBMS in which the database is organized and
accessed according to the relationships between data
values. RDBMS are designed to take care of large amounts
of data and also the security of this data
Data Definition Language (DDL), Data Definition Language (DDL), Data Manipulation Language (DML) , Transaction Control Language (TCL) , Data Control Language (DCL) - , SQL Constraints
Presented by,
Mr. Abhilash K
Database Architect, Livares Technologies
Introduction
About DBMS
A database management system (DBMS) is a software for
creating and managing databases. DBMS provides
users/programmers with a systematic way to create,
retrieve, update and manage data.
What is RDBMS
A type of DBMS in which the database is organized and
accessed according to the relationships between data
values. RDBMS are designed to take care of large amounts
of data and also the security of this data
Data Definition Language (DDL), Data Definition Language (DDL), Data Manipulation Language (DML) , Transaction Control Language (TCL) , Data Control Language (DCL) - , SQL Constraints
Your Digital Assistant.
Making complex approach simple. Straightforward process saves time. No more waiting to connect with people that matter to you. Safety first is not a cliché - Securely protect information in cloud storage to prevent any third party from accessing data.
Would you rather make your visitors feel burdened by making them wait? Or choose VizMan for a stress-free experience? VizMan is an automated visitor management system that works for any industries not limited to factories, societies, government institutes, and warehouses. A new age contactless way of logging information of visitors, employees, packages, and vehicles. VizMan is a digital logbook so it deters unnecessary use of paper or space since there is no requirement of bundles of registers that is left to collect dust in a corner of a room. Visitor’s essential details, helps in scheduling meetings for visitors and employees, and assists in supervising the attendance of the employees. With VizMan, visitors don’t need to wait for hours in long queues. VizMan handles visitors with the value they deserve because we know time is important to you.
Feasible Features
One Subscription, Four Modules – Admin, Employee, Receptionist, and Gatekeeper ensures confidentiality and prevents data from being manipulated
User Friendly – can be easily used on Android, iOS, and Web Interface
Multiple Accessibility – Log in through any device from any place at any time
One app for all industries – a Visitor Management System that works for any organisation.
Stress-free Sign-up
Visitor is registered and checked-in by the Receptionist
Host gets a notification, where they opt to Approve the meeting
Host notifies the Receptionist of the end of the meeting
Visitor is checked-out by the Receptionist
Host enters notes and remarks of the meeting
Customizable Components
Scheduling Meetings – Host can invite visitors for meetings and also approve, reject and reschedule meetings
Single/Bulk invites – Invitations can be sent individually to a visitor or collectively to many visitors
VIP Visitors – Additional security of data for VIP visitors to avoid misuse of information
Courier Management – Keeps a check on deliveries like commodities being delivered in and out of establishments
Alerts & Notifications – Get notified on SMS, email, and application
Parking Management – Manage availability of parking space
Individual log-in – Every user has their own log-in id
Visitor/Meeting Analytics – Evaluate notes and remarks of the meeting stored in the system
Visitor Management System is a secure and user friendly database manager that records, filters, tracks the visitors to your organization.
"Secure Your Premises with VizMan (VMS) – Get It Now"
Cyaniclab : Software Development Agency Portfolio.pdfCyanic lab
CyanicLab, an offshore custom software development company based in Sweden,India, Finland, is your go-to partner for startup development and innovative web design solutions. Our expert team specializes in crafting cutting-edge software tailored to meet the unique needs of startups and established enterprises alike. From conceptualization to execution, we offer comprehensive services including web and mobile app development, UI/UX design, and ongoing software maintenance. Ready to elevate your business? Contact CyanicLab today and let us propel your vision to success with our top-notch IT solutions.
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus
As part of the DOE Integrated Research Infrastructure (IRI) program, NERSC at Lawrence Berkeley National Lab and ALCF at Argonne National Lab are working closely with General Atomics on accelerating the computing requirements of the DIII-D experiment. As part of the work the team is investigating ways to speedup the time to solution for many different parts of the DIII-D workflow including how they run jobs on HPC systems. One of these routes is looking at Globus Compute as a way to replace the current method for managing tasks and we describe a brief proof of concept showing how Globus Compute could help to schedule jobs and be a tool to connect compute at different facilities.
Software Engineering, Software Consulting, Tech Lead.
Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Security,
Spring Transaction, Spring MVC,
Log4j, REST/SOAP WEB-SERVICES.
How Recreation Management Software Can Streamline Your Operations.pptxwottaspaceseo
Recreation management software streamlines operations by automating key tasks such as scheduling, registration, and payment processing, reducing manual workload and errors. It provides centralized management of facilities, classes, and events, ensuring efficient resource allocation and facility usage. The software offers user-friendly online portals for easy access to bookings and program information, enhancing customer experience. Real-time reporting and data analytics deliver insights into attendance and preferences, aiding in strategic decision-making. Additionally, effective communication tools keep participants and staff informed with timely updates. Overall, recreation management software enhances efficiency, improves service delivery, and boosts customer satisfaction.
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Shahin Sheidaei
Games are powerful teaching tools, fostering hands-on engagement and fun. But they require careful consideration to succeed. Join me to explore factors in running and selecting games, ensuring they serve as effective teaching tools. Learn to maintain focus on learning objectives while playing, and how to measure the ROI of gaming in education. Discover strategies for pitching gaming to leadership. This session offers insights, tips, and examples for coaches, team leads, and enterprise leaders seeking to teach from simple to complex concepts.
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTier1 app
Even though at surface level ‘java.lang.OutOfMemoryError’ appears as one single error; underlyingly there are 9 types of OutOfMemoryError. Each type of OutOfMemoryError has different causes, diagnosis approaches and solutions. This session equips you with the knowledge, tools, and techniques needed to troubleshoot and conquer OutOfMemoryError in all its forms, ensuring smoother, more efficient Java applications.
Designing for Privacy in Amazon Web ServicesKrzysztofKkol1
Data privacy is one of the most critical issues that businesses face. This presentation shares insights on the principles and best practices for ensuring the resilience and security of your workload.
Drawing on a real-life project from the HR industry, the various challenges will be demonstrated: data protection, self-healing, business continuity, security, and transparency of data processing. This systematized approach allowed to create a secure AWS cloud infrastructure that not only met strict compliance rules but also exceeded the client's expectations.
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Globus
The U.S. Geological Survey (USGS) has made substantial investments in meeting evolving scientific, technical, and policy driven demands on storing, managing, and delivering data. As these demands continue to grow in complexity and scale, the USGS must continue to explore innovative solutions to improve its management, curation, sharing, delivering, and preservation approaches for large-scale research data. Supporting these needs, the USGS has partnered with the University of Chicago-Globus to research and develop advanced repository components and workflows leveraging its current investment in Globus. The primary outcome of this partnership includes the development of a prototype enterprise repository, driven by USGS Data Release requirements, through exploration and implementation of the entire suite of the Globus platform offerings, including Globus Flow, Globus Auth, Globus Transfer, and Globus Search. This presentation will provide insights into this research partnership, introduce the unique requirements and challenges being addressed and provide relevant project progress.
A Comprehensive Look at Generative AI in Retail App Testing.pdfkalichargn70th171
Traditional software testing methods are being challenged in retail, where customer expectations and technological advancements continually shape the landscape. Enter generative AI—a transformative subset of artificial intelligence technologies poised to revolutionize software testing.
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar
The European Union Agency for Law Enforcement Cooperation (Europol) has suffered an alleged data breach after a notorious threat actor claimed to have exfiltrated data from its systems. Infamous data leaker IntelBroker posted on the even more infamous BreachForums hacking forum, saying that Europol suffered a data breach this month.
The alleged breach affected Europol agencies CCSE, EC3, Europol Platform for Experts, Law Enforcement Forum, and SIRIUS. Infiltration of these entities can disrupt ongoing investigations and compromise sensitive intelligence shared among international law enforcement agencies.
However, this is neither the first nor the last activity of IntekBroker. We have compiled for you what happened in the last few days. To track such hacker activities on dark web sources like hacker forums, private Telegram channels, and other hidden platforms where cyber threats often originate, you can check SOCRadar’s Dark Web News.
Stay Informed on Threat Actors’ Activity on the Dark Web with SOCRadar!
Understanding Globus Data Transfers with NetSageGlobus
NetSage is an open privacy-aware network measurement, analysis, and visualization service designed to help end-users visualize and reason about large data transfers. NetSage traditionally has used a combination of passive measurements, including SNMP and flow data, as well as active measurements, mainly perfSONAR, to provide longitudinal network performance data visualization. It has been deployed by dozens of networks world wide, and is supported domestically by the Engagement and Performance Operations Center (EPOC), NSF #2328479. We have recently expanded the NetSage data sources to include logs for Globus data transfers, following the same privacy-preserving approach as for Flow data. Using the logs for the Texas Advanced Computing Center (TACC) as an example, this talk will walk through several different example use cases that NetSage can answer, including: Who is using Globus to share data with my institution, and what kind of performance are they able to achieve? How many transfers has Globus supported for us? Which sites are we sharing the most data with, and how is that changing over time? How is my site using Globus to move data internally, and what kind of performance do we see for those transfers? What percentage of data transfers at my institution used Globus, and how did the overall data transfer performance compare to the Globus users?
Experience our free, in-depth three-part Tendenci Platform Corporate Membership Management workshop series! In Session 1 on May 14th, 2024, we began with an Introduction and Setup, mastering the configuration of your Corporate Membership Module settings to establish membership types, applications, and more. Then, on May 16th, 2024, in Session 2, we focused on binding individual members to a Corporate Membership and Corporate Reps, teaching you how to add individual members and assign Corporate Representatives to manage dues, renewals, and associated members. Finally, on May 28th, 2024, in Session 3, we covered questions and concerns, addressing any queries or issues you may have.
For more Tendenci AMS events, check out www.tendenci.com/events
How to Position Your Globus Data Portal for Success Ten Good PracticesGlobus
Science gateways allow science and engineering communities to access shared data, software, computing services, and instruments. Science gateways have gained a lot of traction in the last twenty years, as evidenced by projects such as the Science Gateways Community Institute (SGCI) and the Center of Excellence on Science Gateways (SGX3) in the US, The Australian Research Data Commons (ARDC) and its platforms in Australia, and the projects around Virtual Research Environments in Europe. A few mature frameworks have evolved with their different strengths and foci and have been taken up by a larger community such as the Globus Data Portal, Hubzero, Tapis, and Galaxy. However, even when gateways are built on successful frameworks, they continue to face the challenges of ongoing maintenance costs and how to meet the ever-expanding needs of the community they serve with enhanced features. It is not uncommon that gateways with compelling use cases are nonetheless unable to get past the prototype phase and become a full production service, or if they do, they don't survive more than a couple of years. While there is no guaranteed pathway to success, it seems likely that for any gateway there is a need for a strong community and/or solid funding streams to create and sustain its success. With over twenty years of examples to draw from, this presentation goes into detail for ten factors common to successful and enduring gateways that effectively serve as best practices for any new or developing gateway.
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisGlobus
JASMIN is the UK’s high-performance data analysis platform for environmental science, operated by STFC on behalf of the UK Natural Environment Research Council (NERC). In addition to its role in hosting the CEDA Archive (NERC’s long-term repository for climate, atmospheric science & Earth observation data in the UK), JASMIN provides a collaborative platform to a community of around 2,000 scientists in the UK and beyond, providing nearly 400 environmental science projects with working space, compute resources and tools to facilitate their work. High-performance data transfer into and out of JASMIN has always been a key feature, with many scientists bringing model outputs from supercomputers elsewhere in the UK, to analyse against observational or other model data in the CEDA Archive. A growing number of JASMIN users are now realising the benefits of using the Globus service to provide reliable and efficient data movement and other tasks in this and other contexts. Further use cases involve long-distance (intercontinental) transfers to and from JASMIN, and collecting results from a mobile atmospheric radar system, pushing data to JASMIN via a lightweight Globus deployment. We provide details of how Globus fits into our current infrastructure, our experience of the recent migration to GCSv5.4, and of our interest in developing use of the wider ecosystem of Globus services for the benefit of our user community.
Modern design is crucial in today's digital environment, and this is especially true for SharePoint intranets. The design of these digital hubs is critical to user engagement and productivity enhancement. They are the cornerstone of internal collaboration and interaction within enterprises.
3. Relational Database Management System
• A relational database can be defined informally as: A relational database is a database
where all data visible to the user is organized strictly as tables of data values, and where all
database operations work on these tables.
• From the definition it is known that the organizing principle in a relational database is the
table, a rectangular, two-dimensional arrangement of data values.
4. TABLES
• Each table has a unique table name that identifies its contents. Each
column in a table has a column name, which is at the top of the column.
• The columns of a table must all have different names. The data in each
column is of the same type.
• Each row of a table contains exactly one data value in each column.
The rows in a table do not have any particular order.
• A table can have any number of rows. A table of zero rows is
called an empty table, which means it contains no data.
5. Introduction to SQL Language
• SQL is an abbreviation for Structured Query Language (pronounced "ess- que-
el").SQL is used to communicate with a database meaning, it is a tool for
organizing, managing, and retrieving data stored in a database.
• According to ANSI (American National Standards Institute), it is the standard
language for relational database management systems (RDBMS).
• SQL statements are used to perform tasks such as update data on a database, or
retrieve data from a database.
• Some common relational database management systems that use SQL are:
Oracle, Sybase, Microsoft SQL Server, Access, Ingress, Mysql, etc.
6. • To allow access to the information in a database, SQL defines the
reserved words (operations, functions and commands) of the
language which indicates the actions to be performed on the
database.
• These words are described by Data Definition Language (DDL)
and Data Manipulation Language (DML).
• The DDL commands allow us to create and define new
databases, fields and indexes while the DML commands let us
build queries to sort, filter and extract data from the database
7. DDL Commands
• CREATE used to create new tables, fields and indexes.
• DROP is used to delete tables and indexes from the databases.
• ALTER is used to modify tables by adding fields or changing field
definitions.
DML Commands
• SELECT is used to query the database.
• INSERT is used to load data into the database.
• UPDATE is used to change the values of particular records and
fields.
• DELETE is used to remove records from a database.
8. Why choose MySQL?
• 1. Speed. Developers claims it's the fastest
(http//:www.mysql.com/benchmark.html)
• 2. Ease of Use Simple administrations and installations
• 3. Its free
• 4. Query Language Support Supports SQL
• 5. Capability
• 6. Connectivity and Security Accessed from whereever you are and supports
flixable access control
• 7. Portability: Run on Linux, Unix, Solaris , FreeBSD ,Windows , etc
• 8. Open source
9. Mysql Installation
•UseWamp server to install mysql server, we will
use the wamp server to get phpmyadmin also.
•You are done and ready to use the system!!
10. Issuing Queries (General Queries)
• Connect to database server either remotely or locally and type
the following commands:
mysql> SELECT NOW();
mysql> SELECT NOW ();
mysql> SELECT NOW(),VERSION();
mysql> SHOW DATABASES;
mysql> USE mysql;
mysql> SHOWTABLES;
mysql> DESCRIBE USER;
11. Database related SQL (create a database )
To create a database :
CREATE DATABASE db_name
To delete a database and all the tables inside:
DROP DATABASE db_name
To list all the databases in the server :
SHOW DATABASES
To set the default database for the current session :
USE db_name
12. Create aTable
This is an example of the CREATETABLE sql :
CREATETABLE HeadOfState (
ID INT NOT NULL,
LastName CHAR(30) NOT NULL,
FirstName CHAR(30) NOT NULL );
13. Note : We can examine the table structure using
SHOW CREATETABLE tbl_name
Which shows the CREATETABLE statement that creates the given table. Alternatively
we can use the below statement to display more user friendly table description:
DESCRIBE table_name
To list all the tables in the current database:
SHOWTABLES
To drop a table and all its data:
DROPTABLE table_name
To display all the data in a table:
SELECT * FROM table_name
14. CreatingTables Based on ExistingTables
MySQL provides two ways to create a table based on another table:
CREATETABLE ... SELECT creates a table and populates it from the result set
returned by an arbitrary SELECT statement. In this case, the "other table" is the set of
rows and columns retrieved by the SELECT.
CREATETABLE ... LIKE creates an empty table using the definition of another
existing table.
CREATETABLE ... SELECT can create a table that is empty or non-empty, depending
on what is returned by the SELECT part.
15. The result is a new table with a definition that includes all column attributes and
indexes of the original table. Suppose that table t looks like this:
CREATETABLE t
(i INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (i))
ENGINE = MyISAM;
The result of CREATE TABLE ... LIKE differs from the result of using CREATE
TABLE ... SELECT to create an empty table. Either of the following statements will
create an empty copy of the table t:
mysql> CREATE TABLE copy1 SELECT * FROM t WHERE 0;
mysql> CREATE TABLE copy2 LIKE t;
16. However, the resulting copies differ in the amount of information retained from the original table structure:
mysql> SHOW CREATETABLE copy1G;
*************************** 1. row ***************************
Table: copy1
Create Table: CREATETABLE ‘copy1 ‘ (
‘i ‘ int(11) NOT NULL default '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1
mysql> SHOW CREATETABLE copy2G;
*************************** 1. row ***************************
Table: copy2
Create Table: CREATETABLE ‘copy2 ‘ (
‘i ‘ int(11) NOT NULL auto_increment,
PRIMARY KEY (i ‘)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
17. Adding and Dropping Columns
To add a new column to a table, use ALTERTABLE with an ADD clause that specifies
the column's definition. A column definition uses the same syntax for ALTERTABLE
as for CREATE TABLE. For example, to add a DATE column named Inauguration
you can issue this statement:
ALTERTABLE HeadOfState ADD Inauguration DATE NOT NULL;
That ALTERTABLE statement changes the table structure as follows:
mysql> DESCRIBE HeadOfState;
18. To indicate that MySQL should place the new column in a specific position within the
table, append either the keyword FIRST or the keyword-identifier combination
AFTER column_name to the column definition. For example, assume that you had
executed this ALTERTABLE statement instead of the previous one:
ALTERTABLE HeadOfState ADD Inauguration DATE NOT NULL FIRST;
The FIRST keyword tells ALTERTABLE to place the new column before all existing
columns (in the "first" position), resulting in the following table structure:
mysql> DESCRIBE HeadOfState;
19. Using AFTER column_name tells ALTERTABLE to place the new column
after a specific existing column. For example, to place the new Inauguration
column after the existing FirstName column, you would issue this statement:
ALTERTABLE HeadOfState ADD Inauguration DATE NOT NULL AFTER
FirstName;
That ALTERTABLE statement results in a table structure that looks like this:
mysql> DESCRIBE HeadOfState;
20. Column names within a table must be unique, so you cannot add a column
with the same name as one that already exists in the table. Also, column
names are not case sensitive, so if the table already contains a column named
ID, you cannot add a new column using any of these names: ID, id, Id, or iD.
They all are considered to be the same name.
To drop a column, use a DROP clause that names the column to be removed:
ALTERTABLE table_name DROP column_name;
21. Modifying Existing Columns
There are two ways to change the definition of an existing column within a table. One
of these also enables you to rename the column.
The first way to alter a column definition is to use a MODIFY clause. You must specify
the name of the column that you want to change, followed by its new definition.
Assume that you want to change the ID column's data type from INT to BIGINT, to
allow the table to accommodate larger identification numbers. You also want to make
the column UNSIGNED to disallow negative values. The following statement
accomplishes this task:
ALTERTABLE HeadOfState MODIFY ID BIGINT UNSIGNED NOT NULL;
DESCRIBE or (DESC) now shows the table structure to be as follows:
mysql> DESCRIBE HeadOfState;
22. The second way to alter a column definition is to use a CHANGE clause. CHANGE
enables you to modify both the column's definition and its name. To use this clause,
specify the CHANGE keyword, followed by the column's existing name, its new
name, and its new definition, in that order. Note that this means you must specify the
existing name twice if you want to change only the column definition (and not the
name). For example, to change the LastName column from CHAR(30) to CHAR(40)
without renaming the column, you'd do this:
ALTERTABLE HeadOfState CHANGE LastName LastName CHAR(40) NOT NULL;
To change the name as well (for example, to Surname), provide the new name
following the existing name:
ALTERTABLE HeadOfState CHANGE LastName Surname CHAR(40) NOT NULL;
23. Renaming aTable
Renaming a table changes neither a table's structure nor its contents. The following statement renames
table t1 to t2:
ALTERTABLE t1 RENAMETO t2;
Another way to rename a table is by using the RENAMETABLE statement:
RENAMETABLE t1TO t2;
RENAME TABLE has an advantage over ALTER TABLE in that it can perform multiple table renames in a
single operation. One use for this feature is to swap the names of two tables:
RENAMETABLE t1TO tmp, t2TO t1, tmpTO t2;
For TEMPORARY tables, RENAMETABLE does not work.You must use ALTERTABLE instead.
ALTERTABLE HeadOfState MODIFY ID BIGINT UNSIGNED NOT NULL;
24. MySQL DataTypes
Generally there are 3 categories of column type supported
by MySQL which are :
1. NumericType
2. String (Character )Type
3. Date andTimeType
25. Numeric ColumnType
MySQL understands integers, floating points and scientific
notations. Numbers can be preceded by a minus sign to indicate
negative value. Following is the column type available (commonly
used in MySQL).
INT,TINYINT, SMALLINT, INT, FLOAT, DOUBLE, DECIMAL,
Usage example:
TINYINT[(M)] [UNSIGNED] [ZEROFILL]
DOUBLE [(M,D)] [ZEROFILL]
26. String ColumnTypes
CHAR,VARCHAR,TINYBLOB,BLOB,MEDIUMBLOB,LONGBLOB,TINYTEXT,TEXT,
MEDIUMTEXT,LONGTEXT,ENUM,SET
example:
nameVARCHAR(20) NOT NULL,
In Numeric Column Type, the number inside the parenthesis indicates display number, but in over here it is not.
It explicitly defined the length of the character.
Only CHAR and VARCHAR s' length can be defined. Strings are actually a 'generic' type in a sense because it
can be used to hold any values.
VARCHAR and CHAR are the most common type. CHAR is fixed length type while the VARCHAR is variable
length type. BLOB is a binary large object which can hold anything you throw into it. The variation indicates
different maximum number of information can be stored. TEXT type is identical to BLOB, but different in the
sense that BLOB is case sensitive while TEXT is case insensitive. (This matters when sorting and comparing is
used).
27. ENUM and SET
• ENUM and SET are special type for which colomn values must be chosen
from a fixed set of strings.
• Difference is ENUM column values must have at least exactly one member
of the set while SET may contain any or all members of the set.
28. Date andTime ColumnType
• DATE,TIME, DATETIME,TIMESTAMP,YEAR
• Values of TIME type are elapsed time. A 12:30:00 means 12 hours, and 30
minutes and not 12.30 am which means that TIME can hold values like
50:13:00 but not 50:65:00
• If TIMESTAMP column is set to "NULL" then automatically it will be set to
current time and date.
• M inTIMEFORMAT indicates display formats
29. Attributes
A. Numeric ColumnType
1. AUTO_INCREMENT Indicates that the value is automatically increased by 1
from the previous value. For any column to be used as auto_increment must
be declared as NOT NULL and PRIMARY KEY / UNIQUE KEY
2. UNSIGNED Disallows negative numbers
B. String ColumnTypes
1. Binary Specified for CHAR or VARCHAR, which causes the column values to
be treated as binary strings.
2. NULL or NOT NULL
3. DEFAULT To specify a default value for CHAR or VARCHAR only.
30. Inserting into aTable
The INSERT statement is used to insert or add a new row of data into a table, below
we have the two forms of the insert statement:
INSERT INTO table_name (column_list) VALUES (value_list);
INSERT INTO table_name SET column_name = value [, column_name2
= value2] ... ;
For any column not assigned an explicit value by an INSERT statement, MySQL sets
it to its default value if it has one. For example, to have MySQL set the id column to
its default, you can simply omit it from the statement.The following example shows
statements using each INSERT syntax that assign no explicit id value:
Examples :
INSERT INTO people (name,age) VALUES('William',25);
INSERT INTO people SET name = 'William', age = 25;
32. Retrieving Non specific Data
SELECT command is used to retrieve data from tables.The simplest retrieval is when
you ask for all the data in a table. Following command retrieve all data from table
named 'animal'
SELECT * FROM animals
This statement returns all the data in all the rows and columns of the table 'animals'.
The asterisk (*) is a wildcard character means "all attributes ".
33. Retrieving Specific Data
SELECT command can be used to query the database and retrieve selected data that
match the certain criteria. These is easily achieved by adding "WHERE" clause to the
SELECT statement above. Here is the format of a simple select statement:
SELECT "column1" [,"column2", etc] FROM tbl_name [where
"condition"];
Example:
SELECT * FROM animals WHERE gender='f' AND species='cat';
Expression in WHERE clause can use arithmetic operators, comparison operators and
logical operators as below
Arithmetic Operators+ :, - , * and /
Comparison Operators= : , > , >= , ) =! <> ) , >= and >
Logical Operator: AND, OR, NOT
Others: BETWEEN, Like
34. Specifying Which Rows to Retrieve
If you specify no criteria for selecting records from a table, a SELECT
statement retrieves every record in the table. This is often more information
than you need, particularly for large tables. To be more specific about which
rows are of interest, include a WHERE clause that describes the characteristics
of those rows.
• SELECT * FROM Country WHERE IndepYear > 1990;
• SELECT * FROM Country WHERE Population >= 1000000 AND
Population <= 2000000;
• SELECT * FROM Country WHERE Population BETWEEN 1000000 AND
2000000;
35. Using ORDER BY to Sort Query Results
By default, the rows in the result set produced by a SELECT statement are
returned by the server to the client in no particular order. If you require output
rows to be returned in a specific order, include an ORDER BY clause that
indicates how to sort the results. The examples in this section demonstrate
ORDER BY:
• SELECT id, last_name, first_name, birth FROM t ORDER BY birth;
• SELECT id, last_name, first_name, birth FROM t ORDER BY last_name,
first_name;
• SELECT id, last_name, first_name, birth FROM t ORDER BY id DESC;
36. Limiting a Selection Using LIMIT
MySQL supports a LIMIT clause in SELECT statements, which tells the server to
return only some of the rows selected by the statement. This is useful for retrieving
records based on their position within the set of selected rows. LIMIT may be given
with either one or two arguments:
LIMIT row_count
LIMIT skip_count, row_count
SELECT * FROM Country LIMIT 10;
SELECT * FROM Country LIMIT 20,10;
37. Deleting Records
To remove records from tables, use a DELETE statement or a trUNCATE TABLE statement. The
DELETE statement allows a WHERE clause that identifies which records to remove, whereas
TRUNCATETABLE always removes all records. DELETE therefore can be more precise in its effect.
To empty a table entirely by deleting all its records, you can use either of the following statements:
DELETE FROM table_name;
TRUNCATETABLE table_name;
To remove only specific records in a table, trUNCATE TABLE cannot be used. You must issue a
DELETE statement that includes a WHERE clause that identifies which records to remove:
DELETE FROM table_name WHERE ... ;
38. Updating Records
The UPDATE statement is used to update or change records that match
specified criteria. This is accomplished by carefully constructing a where
clause.
UPDATE table_name
SET column_name = value [, column_name = value] ...
WHERE ... ;
39. Using DISTINCT to Eliminate Duplicates
If a query returns a result that contains duplicate rows, you can remove
duplicates to produce a result set in which every row is unique. To do this,
include the keyword DISTINCT after SELECT and before the output column
list.
Suppose that a query returns a result set that contains duplicated rows:
mysql> SELECT last_name FROM t;
Adding DISTINCT removes the duplicates and returns only unique rows:
mysql> SELECT DISTINCT last_name FROM t;
40. Aggregating Results
A SELECT statement can produce a list of rows that match a given set of
conditions. The list provides the details about the selected rows, but if you
want to know about the overall characteristics of the rows, you'll be more
interested in getting a summary instead. When that's your goal, use aggregate
functions to calculate summary values, possibly combined with a GROUP BY
clause to arrange the selected rows into groups so that you can get summaries
for each group. Grouping can be based on the values in one or more columns
of the selected rows.
41. There are several types of aggregate functions.Those discussed
here are as follows:
• MIN() and MAX() find smallest and largest values.
• SUM() and AVG() summarize numeric values to produce sums
(totals) and averages.
• COUNT() counts rows, values, or the number of distinct values.
42. The MIN() and MAX() Aggregate Functions
MIN() and MAX() are comparison functions. They return smallest or largest numeric
values, lexically first or last string values, and earliest or latest temporal values. The
following queries determine the smallest and largest country populations and the
lexically first and last country names:
mysql> SELECT MIN(Population), MAX(Population) FROM Country;
mysql> SELECT MIN(Name), MAX(Name) FROM Country;
MIN() and MAX() ignore NULL values.
43. The SUM() and AVG() Aggregate Functions
The SUM() and AVG() functions calculate sums and averages. For example,
the Country table in the world database contains a Population column, so
you can calculate the total world population and the average population per
country like this:
mysql> SELECT SUM(Population), AVG(Population) FROM Country;
SUM() and AVG() ignore NULL values.
44. COUNT() Aggregate Function
The COUNT() function can be used in several ways to count either rows or values. To
illustrate, the examples here use the following table that has several rows containing
various combinations of NULL and non-NULL values:
SELECT COUNT(i), COUNT(j) FROM t;
COUNT(DISTINCT expression) counts the number of distinct (unique) non-NULL
values of the given expression. expression can be a column name to count the
number of distinct non-NULL values in the column:
SELECT COUNT(DISTINCT i), COUNT(DISTINCT j) FROM t;
SELECT COUNT(DISTINCT i, j) FROM t;
45. Grouping Results
If a query does not contain a GROUP BY clause to place rows of the result set into
groups, an aggregate function produces a result that is based on all the selected rows.
A GROUP BY clause may be added to generate a more fine-grained summary that
produces values for subgroups within a set of selected rows.
Adding a GROUP BY clause arranges rows using the values in the grouping column or
columns.The result is that COUNT(*) produces a count for each group.To find out
how many times each title occurs, do this:
• SELECT title, COUNT(*) FROM personnel GROUP BY title;
• SELECT dept_id, title, COUNT(*) FROM personnel GROUP BY dept_id, title;
46. GROUP BY and Sorting
In MySQL, a GROUP BY clause has the side effect of sorting rows. If you
already have a GROUP BY clause in your query that produces the desired sort
order, there's no need for an ORDER BY. Use of ORDER BY is necessary with
GROUP BY only to produce a different sort order than that resulting from the
GROUP BY. However, this isn't a portable behavior. For database engines
other than MySQL, GROUP BY might not sort rows. To write more portable
queries, add an ORDER BY even if MySQL does not require it.
47. Selecting Groups with HAVING
It could be when you use GROUP BY that you're interested only in groups that have
particular summary characteristics. To retrieve just those groups and eliminate the
rest, use a HAVING clause that identifies the required group characteristics. HAVING
acts in a manner somewhat similar to WHERE, but occurs at a different stage of query
processing:
1.WHERE, if present, identifies the initial set of records to select from a table.
2. GROUP BY arranges the selected records into groups.
3. Aggregate functions compute summary values for each group.
4. HAVING identifies which groups to retrieve for the final result set.
mysql> SELECT title, salary, COUNT(*), AVG(salary)
-> FROM personnel WHERE dept_id = 7
-> GROUP BY title
-> HAVING COUNT(*)> 1;
49. Joins
• When it's necessary to draw on information that is stored in multiple tables, use a join—
an operation that produces a result by combining (joining) information in one table with
information in another.
• A join between tables is an extension of a single-table SELECT statement, but involves
the following additional complexities:
• The FROM clause names all the tables needed to produce the query result, not just one
table.
• A join that matches records in one table with records in another must specify how to
match up the records. These conditions often are given in the WHERE clause, but the
particular syntax depends on the type of join.
1. SELECT Name, Language FROM CountryLanguage, Country WHERE CountryCode = Code;
2. SELECT Name, Language FROM Country INNER JOIN CountryLanguage ON Code =
CountryCode;
50. Outer Join
• An inner join produces results by selecting combinations of matching rows from the joined tables.
• However, it cannot find nonmatches; that is, instances where a row in one table has no match in
another table.
• An outer join finds matches (just like an inner join), but also identifies mismatches.
• Furthermore, with an appropriate WHERE clause, an outer join can filter
out matches to display only the mismatches.
• Two common forms of outer joins are left joins and right joins.
• These are written using the LEFT JOIN or RIGHT JOIN keywords rather than the comma operator
or the INNER JOIN keywords.
51. Outer Join
• A left join is a type of outer join, written using the LEFT JOIN keywords.
• A left join treats the left table (the first one named) as a reference table and produces output for
each row selected from it, whether or not the row is matched by rows in the right table.
• A LEFT JOIN is written using either ON or USING()after the table names in the FROM clause.
• The example here uses the ON syntax:
SELECT Name, Language FROM Country LEFT JOIN CountryLanguage ON Code = CountryCode;
• In this query, the left table is the one named first (Country) and the right table is the one named
second (CountryLanguage).
52. Outer Join
• A right join is another type of outer join, written using the RIGHT JOIN keywords.
• Every right join corresponds to an equivalent left join.
• The only difference is that the roles of the tables in a right join are reversed relative to the
roles in a left join.
• That is, the right table is the reference table, so a RIGHT JOIN produces a result for each row
in the right table, whether or not it has any match in the left table.
53. Updating and Deleting MultipleTables
• MySQL allows the use of join syntax in UPDATE and DELETE statements to enable updates or
deletes that involve multiple tables.
• Some of the principles involved in writing joins in SELECT statements also apply to multiple-table
UPDATE and DELETE statements. This section provides a brief overview of their syntax.
• A multiple-table UPDATE is an extension of a single-table statement:
• Following the UPDATE keyword, name the tables involved in the operation, separated by commas. (You must name all the
tables used in the query, even if you aren’t updating all of them.)
• In the WHERE clause, describe the conditions that determine how to match records in the tables.
• In the SET clause, assign values to the columns to be updated. These assignments can refer to columns from any of the
joined tables.
UPDATE t1, t2 SET t1.name = t2.name WHERE t1.id = t2.id;
54. Updating and Deleting MultipleTables
• Multiple-table DELETE statements can be written in two formats.
• The following example demonstrates one syntax, for a query that deletes rows from a table t1
where the id values match those in a table t2:
DELETE t1 FROM t1, t2 WHERE t1.id = t2.id;
• The second syntax is slightly different:
DELETE FROM t1 USING t1, t2 WHERE t1.id = t2.id;
• The ORDER BY and LIMIT clauses normally supported by UPDATE and DELETE aren’t
allowed when these statements are used for multiple-table operations.
55. SQL Expressions
• Expressions are a common element of SQL statements, and they occur in many contexts.
• For example, expressions often occur in the WHERE clause of SELECT, DELETE, or
UPDATE statements to identify which records to retrieve, delete, or update.
• But expressions may be used in many other places; for example, in the output column list of a
SELECT statement, or in ORDER BY or GROUP BY clauses.
• Expressions use different types of values like : Table columns, Literal values, or Functions.
56. String Expressions
• Literal strings in expressions are written as quoted values.
• By default, either single quotes or double quotes can be used, although single quotes are more standard.
• The data types for representing strings in tables include CHAR, VARCHAR, BINARY, VARBINARY, and the TEXT and
BLOB types.
• String concatenation is done with the CONCAT() function:
SELECT CONCAT('abc','def');
+-----------------------------------+
| CONCAT('abc','def’) |
+-----------------------------------+
| abcdef |
+-----------------------------------+
• UPPER() and LOWER() functions perform case conversion only if the argument is a non-binary
string.
SELECT UPPER('AbCd'), LOWER('AbCd');
+---------------+---------------+
| UPPER('AbCd') | LOWER('AbCd') |
+---------------+---------------+
| ABCD |abcd |
+---------------+---------------+
57. Using LIKE for Pattern Matching
• Operators such as = and =! are useful for finding values that are equal to or not equal to a
specific exact comparison value.
• When it's necessary to find values based on similarity instead, a pattern match is useful.
• To perform a pattern match, use value LIKE 'pattern', where value is the value you want to test
and 'pattern' is a pattern string that describes the general form of values that you want to
match.
• Patterns used with the LIKE pattern-matching operator can contain two special characters
(called "metacharacters" or "wildcards "( that stand for something other than themselves:
• The '%' character matches any sequence of zero or more characters.
• The '_' (underscore) character matches any single character.
• To match a pattern metacharacter literally, escape it by preceding it by a backslash.
58. Using LIKE for Pattern Matching
SELECT 'AA' LIKE 'A%', 'AA' LIKE 'A%', 'A%' LIKE 'A%';
+-----------------+-----------------+----------------+
| 'AA' LIKE 'A%’ | 'AA' LIKE 'A%' | 'A%' LIKE 'A%'|
+-----------------+-----------------+----------------+
| 1| 0| 1|
+-----------------+-----------------+----------------+
mysql> SELECT 'AA' LIKE 'A_', 'AA' LIKE 'A_', 'A_' LIKE 'A_';
+-----------------+-----------------+----------------+
| 'AA' LIKE 'A_’ | 'AA' LIKE 'A_’ | 'A_' LIKE 'A_'|
+-----------------+-----------------+----------------+
| 1| 0 | 1|
+-----------------+-----------------+----------------+
59. Foreign Key
• InnoDB supports foreign key constraints.
• The syntax for a foreign key constraint definition in the create table statement:
[CONSTRAINT [symbol]] FOREIGN KEY
(index_col_name, ...)
REFERENCES tbl_name (index_col_name,...)
[ON DELETE reference_option]
[ON UPDATE reference_option]
reference_option:
RESTRICT | CASCADE | SET NULL | NO ACTION
60. Foreign Key Conditions
1. Both tables must be InnoDB tables and they must not be TEMPORARY tables.
2. Corresponding columns in the foreign key and the referenced key must have similar internal
data types inside InnoDB so that they can be compared without a type conversion. The sign
of integer types must be the same. The length of string types need not be the same. For
nonbinary (character) string columns, the character set and collation must be the same.
3. InnoDB requires indexes on foreign keys and referenced keys so that foreign key checks can
be fast and not require a table scan. In the referencing table, there must be an index where
the foreign key columns are listed as the first columns in the same order. Such an index is
created on the referencing table automatically if it does not exist.
4. InnoDB permits a foreign key to reference any index column or group of columns. However, in
the referenced table, there must be an index where the referenced columns are listed as the
first columns in the same order.
5. If the CONSTRAINT symbol clause is given, the symbol value must be unique in the
database. If the clause is not given, InnoDB creates the name automatically.
61. Foreign Key
• nnoDB rejects any INSERT or UPDATE operation that attempts to create a foreign key value in
a child table if there is no a matching candidate key value in the parent table.
• The action InnoDB takes for any UPDATE or DELETE operation that attempts to update or
delete a candidate key value in the parent table that has some matching rows in the child table
is dependent on the referential action specified using ON UPDATE and ON DELETE
subclauses.
• InnoDB supports four options regarding the action to be taken. If ON DELETE or ON UPDATE
are not specified, the default action is RESTRICT.
1. CASCADE: Delete or update the row from the parent table and automatically delete or update the matching rows in
the child table.
2. SET NULL: Delete or update the row from the parent table and set the foreign key column or columns in the child
table to NULL.
3. NO ACTION, RESTRICT: Attempt to delete or update a primary key value is not permitted to proceed if there is a
related foreign key value in the referenced table.
62. Foreign Key Example
• Here is a simple example that relates parent and child tables through a single-column
foreign key:
CREATE TABLE parent (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
CREATE TABLE child (id INT, parent_id INT, INDEX par_ind (parent_id),
FOREIGN KEY (parent_id) REFERENCES parent(id)
ON DELETE CASCADE) ENGINE=INNODB;
63. MySQLTransactions
• A transaction is a sequential group of database manipulation operations, which is performed
as if it were one single work unit.
• In other words, a transaction will never be complete unless each individual operation within
the group is successful.
• If any operation within the transaction fails, the entire transaction will fail.
• Two keywords Commit and Rollback are mainly used for MySQL Transactions.
• When a successful transaction is completed, the COMMIT command should be issued so
that the changes to all involved tables will take effect.
• If a failure occurs, a ROLLBACK command should be issued to return every table
referenced in the transaction to its previous state.
64. MySQLTransactions Example
1. Begin transaction by issuing SQL command BEGIN WORK
2. Issue one or more SQL commands like SELECT, INSERT, UPDATE or DELETE
3. Check if there is no error and everything is according to your requirement.
4. If there is any error then issue ROLLBACK command otherwise issue a COMMIT command.
65. Views
• A view is a database object that is defined in terms of a SELECT statement that retrieves the
data you want the view to produce.
• A view can be used to select from regular tables (called "base tables “) or other views.
• In some cases, a view is updatable and can be used with statements such as UPDATE,
DELETE, or INSERT to modify an underlying base table.
• To define a view, use the CREATE VIEW statement, which has this syntax:
CREATE [OR REPLACE] [ALGORITHM = algorithm_type]
VIEW view_name [(column_list)]
AS select_statement
[WITH [CASCADED | LOCAL] CHECK OPTION]
66. Views
• view_name is the name to give the view.
• select_statement is a SELECT statement that indicates how to retrieve data when the view is
used. The statement can select from base tables or other views.
• The OR REPLACE clause causes any existing view with same name as the new one to be
dropped prior to creation of the new view.
• The ALGORITHM clause specifies the processing algorithm to use when the view is invoked.
• column_list provides names for the view columns to override the default names.
• When the WITH CHECK OPTION clause is included in a view definition, all data changes
made to the view are checked to ensure that the new or updated rows satisfy the view-
defining condition. If the condition is not satisfied, the change is not accepted, either in the
view or in the underlying base table.
67. Views
• The following CREATE VIEW statement defines a simple view named CityView that selects the ID
and Name columns from the City table. The SELECT statement shows an example of how to
retrieve from the view:
CREATE VIEW CityView AS SELECT ID, Name FROM City;
SELECT * FROM CityView;
+-----------------------------------+
| ID | Name |
+-----------------------------------+
| 1 | Kabul |
| 2 | Qandahar |
| 3 | Herat |
| 4 | Mazar-e-Sharif |
...
• Views and base tables share the same namespace, so CREATE VIEW results in an error if a base
table or view with the given name already exists.