SlideShare una empresa de Scribd logo
1 de 50
PRESENTATION
BY
Sundar.R
 The Data Definition Language (DDL) part of SQL
permits database tables to be created or deleted.
We can also define indexes (keys), specify links
between tables, and impose constraints between
database tables.
 CREATE TABLE - creates a new database table
 ALTER TABLE - alters (changes) a database table
 DROP TABLE - deletes a database
 SQL (Structured Query Language) is a syntax
for executing queries. But the SQL language
also includes a syntax to update, insert, and
delete records.
 SELECT - extracts data from a database
table
 UPDATE - updates data in a database table
 DELETE - deletes data from a database table
 INSERT INTO - inserts new data into a
database table
 To create a database:
 SYNTAX
 CREATE DATABASE database_name ;
 EXAMPLE
 CREATE DATABASE s2i;
 To activate the created database:
 SYNTAX
 USE DATABASE_NAME;
 SYNTAX
 CREATE TABLE table_name(column_name1
data_type,column_name2 data_type,.......) ;
Data Type Description
integer(size)
int(size)
smallint(size)
tinyint(size)
Hold integers only. The maximum
number of digits are specified in
parenthesis.
decimal(size,d)
numeric(size,d
)
Hold numbers with fractions. The
maximum number of digits are
specified in "size". The maximum
number of digits to the right of the
decimal is specified in "d".
char(size) Holds a fixed length string (can
contain letters, numbers, and special
characters). The fixed size is
specified in parenthesis.
varchar(size) Holds a variable length string (can
contain letters, numbers, and special
characters). The maximum size is
specified in parenthesis.
date(yyyymmd
d)
Holds a date
 The INSERT INTO statement is used to insert
new rows into a table.
 SYNTAX
 INSERT INTO table_name VALUES (value1,
value2,....) ;
 INSERT INTO table_name (column1,
column2,...)VALUES (value1, value2,....) ;
 The UPDATE statement is used to modify the
data in a table.
 SYNTAX
 UPDATE table_name SET column1=
new_value WHERE
Old_column1=old_value;
 The ALTER TABLE statement is used to add or
drop columns in an existing table.
 SYNTAX
 ALTER TABLE table_name ADD column_name
data_type;
 The DELETE statement is used to delete rows
in a table.
 Syntax
 DELETE FROM table_name WHERE
column_name = some_value;
 Delete All Rows
 DELETE FROM table_name;
 OR
 DELETE * FROM table_name;
 OR
 TRUNCATE TABLE table_name;
 To delete a table
 DROP TABLE table_name;
 To delete a database
 DROP DATABASE database_name;
 To delete the column in table
 ALTER TABLE table_name DROP COLUMN
column_name;
 The SELECT statement is used to select data
from a table. The tabular result is stored in a
result table (called the result-set).
 Select a table fully
 Syntax
 SELECT * FROM Persons;
 SELECT A COLUMN
 Select column_name from table_name;
 SELECT A ROW
 Select*from table_name where
column_name=‘value’;
 All values stored in mysql is in array formate.
 $var1=mysql_query(“select*from table_name”,
$connection_name);
 While($var=mysql_fetch_array($var1))
 {
 Echo “<br/>”;
 Echo $var[‘column_name’];
 }
 The LIKE & UNLIKE condition is used to
specify a search for a pattern in a column.
 Syntax
 SELECT column FROM table_name WHERE
column_name LIKE pattern;
 SELECT column FROM table_name WHERE
column_name UNLIKE pattern;
 EXAMPLES
 SELECT * FROM table_name WHERE column_name
LIKE 'O%‘;
 SELECT * FROM table_name WHERE column_name
LIKE '%a‘;
 SELECT * FROM table_name WHERE column_name
LIKE '%la%‘;
 The AND & OR operators are used to filter
records based on more than one condition.
 The AND operator displays a record if both
the first condition and the second condition
is true.
 The OR operator displays a record if either
the first condition or the second condition is
true.
 SELECT * FROM table_name WHERE
column1=‘value' AND column2=‘value‘;
 SELECT * FROM table_name WHERE
column1=‘value1' OR column1=‘value2‘;
 SELECT * FROM table_name WHERE
column1=‘value' AND (column2=‘value1' OR
column2=‘value2‘);
 The ORDER BY keyword is used to sort the
result-set by a specified column.
 The ORDER BY keyword sort the records in
ascending order by default.
 If you want to sort the records in a descending
order, you can use the DESC keyword.
 SELECT column_name(s) FROM table_name
ORDER BY column_name(s) ASC|DESC;
 SELECT * FROM table_name ORDER BY
column_name;
 SELECT * FROM table_name ORDER BY
column_name DESC;
 Auto-increment allows a unique number to be
generated when a new record is inserted into a
table.
 CREATE TABLE Persons ( Id int (5)
AUTO_INCREMENT)
 ALTER TABLE Persons AUTO_INCREMENT=100 ;
 The TOP clause is used to specify the number
of records to return.
 The TOP clause can be very useful on large
tables with thousands of records. Returning a
large number of records can impact on
performance.
 Note: Not all database systems support the
TOP clause.
 SELECT column_name(s) FROM table_name LIMIT
number;
 SELECT TOP 2 * FROM table_name;
 SELECT TOP 50 PERCENT * FROM table_name;
 With SQL, aliases can be used for column names
and table names.
 SELECT column AS column_alias FROM table;
 EXAMPLES: SELECT LastName AS Family, FirstName
AS NameFROM Persons;
 SELECT column FROM table AS table_alias;
 EXAMPLE: SELECT LastName, FROM Persons AS
Employees;
 The IN operator allows you to specify multiple
values in a WHERE clause.
 SELECT column_name(s) FROM table_name WHERE
column_name IN (value1,value2,...);
 SELECT * FROM table_name WHERE column IN
(‘value1',‘value2');
 The BETWEEN operator selects a range of data
between two values. The values can be numbers,
text, or dates.
 SELECT column_name(s) FROM table_name WHERE
column_name BETWEEN value1 AND value2;
 SELECT column_name(s) FROM table_name WHERE
column_name NOTBETWEEN value1 AND value2;
 To select only DIFFERENT values from the
column named
 SYNTAX
 SELECT DISTINCT Company FROM Orders;
 Constraints are used to limit the type of data
that can go into a table.
 Constraints can be specified when a table is
created (with the CREATE TABLE statement) or
after the table is created (with the ALTER
TABLE statement).
 NOT NULL
 UNIQUE
 CHECK
 PRIMARY KEY
 FOREIGN KEY
 DEFAULT
 The NOT NULL constraint enforces a column
to NOT accept NULL values.
 CREATE TABLE Persons ( P_Id int NOT NULL,
LastName varchar(255) NOT NULL, FirstName
varchar(255), Address varchar(255), City
varchar(255) )
 The UNIQUE constraint uniquely identifies each
record in a database table.
 CREATE TABLE Persons ( P_Id int NOT NULL,
LastName varchar(255) NOT NULL, FirstName
varchar(255), Address varchar(255), City
varchar(255), UNIQUE (P_Id) );
 Alter table table_name ADD UNIQUE (ID);
 The PRIMARY KEY constraint uniquely
identifies each record in a database
table.
 Primary keys must contain unique values.
 A primary key column cannot contain
NULL values
 CREATE TABLE Persons ( P_Id int NOT
NULL, LastName varchar(255) NOT NULL,
PRIMARY KEY (P_Id) )
 ALTER TABLE Persons ADD PRIMARY KEY
(P_Id)
 A FOREIGN KEY in one table points to a
PRIMARY KEY in another table.
 CREATE TABLE Orders ( O_Id int NOT NULL,
OrderNo int NOT NULL, P_Id int, PRIMARY
KEY (P_Id), FOREIGN KEY (O_Id) REFERENCES
Persons(P_Id) )
 ALTER TABLE Orders ADD FOREIGN KEY (O_Id)
REFERENCES Persons(P_Id)
 The CHECK constraint is used to limit the value
range that can be placed in a column.
 CREATE TABLE Persons ( P_Id int NOT NULL,
LastName varchar(255) NOT NULL, FirstName
varchar(255), Address varchar(255), City
varchar(255), CHECK (P_Id>0) )
 ALTER TABLE Persons ADD CHECK (P_Id>0)
 The DEFAULT constraint is used to insert a
default value into a column.
 CREATE TABLE Persons ( P_Id int NOT NULL,
City varchar(255) DEFAULT 'Sandnes' )
 ALTER TABLE Persons WHERE City SET
DEFAULT 'SANDNES'
 An index can be created in a table to find
data more quickly and efficiently.
 CREATE INDEX index_name ON table_name
(column_name);
 CREATE UNIQUE INDEX index_name ON
table_name (column_name);
 Drop INDEX index_name FROM TABLE_NAME;
 The JOIN keyword is used in an SQL statement to
query data from two or more tables, based on a
relationship between certain columns in these
tables.
 Different SQL JOINS
 INNER JOIN
 OUTER JOIN
 FULL JOIN
 The INNER JOIN keyword return rows when
there is at least one match in both tables.
 SELECT column_name(s) FROM table_name1
INNER JOIN table_name2 ON
table_name1.column_name=table_name2.col
umn_name
 The LEFT JOIN keyword returns all rows from
the left table (table_name1), even if there
are no matches in the right table
(table_name2).
 SELECT column_name(s) FROM table_name1
LEFT JOIN table_name2 ON
table_name1.column_name=table_name2.col
umn_name
 The RIGHT JOIN keyword Return all rows
from the right table (table_name2), even if
there are no matches in the left table
(table_name1).
 SELECT column_name(s) FROM table_name1
RIGHT JOIN table_name2 ON
table_name1.column_name=table_name2.col
umn_name
 The FULL JOIN keyword return rows when
there is a match in one of the tables.
 SELECT column_name(s) FROM table_name1
FULL JOIN table_name2 ON
table_name1.column_name=table_name2.col
umn_name
SQL aggregate functions return a single value,
calculated from values in a column.
 AVG() - Returns the average value
 COUNT() - Returns the number of rows
 FIRST() - Returns the first value
 LAST() - Returns the last value
 MAX() - Returns the largest value
 MIN() - Returns the smallest value
 SUM() - Returns the sum
SQL scalar functions return a single value, based
on the input value.
 UCASE() - Converts a field to upper case
 LCASE() - Converts a field to lower case
 MID() - Extract characters from a text field
 LEN() - Returns the length of a text field
 ROUND() - Rounds a numeric field to the number
of decimals specified
 NOW() - Returns the current system date and
time
 FORMAT() - Formats how a field is to be
displayed
 GROUP BY... was added to SQL because
aggregate functions (like SUM) return the
aggregate of all column values every time
they are called, and without the GROUP BY
function it was impossible to find the sum for
each individual group of column values.
 SELECT column, SUM(column) FROM table GROUP
BY column;
 EXAMPLE: SELECT Company, SUM(Amount) FROM
Sales;
 SELECT Company, SUM(Amount) FROM Sales
GROUP BY Company;
 SELECT column, SUM(column) FROM table GROUP
BY column HAVING SUM(column) condition value;
Statement Syntax
AND / OR SELECT column_name(s)
FROM table_name
WHERE condition
AND|OR condition
ALTER TABLE (add
column)*//
ALTER TABLE table_name
ADD column_name datatype
ALTER TABLE (drop
column)
ALTER TABLE table_name
DROP COLUMN column_name
AS (alias for column) SELECT column_name AS column_alias
FROM table_name
AS (alias for table) SELECT column_name
FROM table_name AS table_alias
BETWEEN SELECT column_name(s)
FROM table_name
WHERE column_name
BETWEEN value1 AND value2
CREATE DATABASE CREATE DATABASE database_name
CREATE INDEX CREATE INDEX index_name
ON table_name (column_name)
CREATE TABLE CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
.......
)
CREATE UNIQUE INDEX CREATE UNIQUE INDEX
index_name
ON table_name (column_name)
CREATE VIEW CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
DELETE FROM DELETE FROM table_name
(Note: Deletes the entire table!!)
or
DELETE FROM table_name
WHERE condition
DROP DATABASE DROP DATABASE database_name
DROP INDEX DROP INDEX table_name.index_name
DROP TABLE DROP TABLE table_name
GROUP BY SELECT
column_name1,SUM(column_name2)
FROM table_name
GROUP BY column_name1
HAVING SELECT
column_name1,SUM(column_name2)
FROM table_name
GROUP BY column_name1
HAVING SUM(column_name2)
condition value
IN SELECT column_name(s)
FROM table_name
WHERE column_name
IN (value1,value2,..)
INSERT INTO INSERT INTO table_name
VALUES (value1, value2,....)
LIKE SELECT column_name(s)
FROM table_name
WHERE column_name
LIKE pattern
ORDER BY SELECT column_name(s)
FROM table_name
ORDER BY column_name
[ASC|DESC]
SELECT SELECT column_name(s)
FROM table_name
SELECT * SELECT *
FROM table_name
SELECT DISTINCT SELECT DISTINCT
column_name(s)
FROM table_name
SELECT INTO
(used to create backup copies
of tables)
SELECT *
INTO new_table_name
FROM original_table_name
or
SELECT column_name(s)
INTO new_table_name
FROM original_table_name
SELECT INTO
(used to create backup copies of tables)
SELECT *
INTO new_table_name
FROM original_table_name
or
SELECT column_name(s)
INTO new_table_name
FROM original_table_name
TRUNCATE TABLE
(deletes only the data inside the table)
TRUNCATE TABLE table_name
UPDATE UPDATE table_name
SET column_name=new_value
[, column_name=new_value]
WHERE column_name=some_value
WHERE SELECT column_name(s)
FROM table_name
WHERE condition

Más contenido relacionado

La actualidad más candente

06.01 sql select distinct
06.01 sql select distinct06.01 sql select distinct
06.01 sql select distinctBishal Ghimire
 
MS SQL Server 1
MS SQL Server 1MS SQL Server 1
MS SQL Server 1Iblesoft
 
Database Management System 1
Database Management System 1Database Management System 1
Database Management System 1Swapnali Pawar
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server iiIblesoft
 
Lecture 3 sql {basics ddl commands}
Lecture 3 sql {basics  ddl commands}Lecture 3 sql {basics  ddl commands}
Lecture 3 sql {basics ddl commands}Shubham Shukla
 
Lecture 4 sql {basics keys and constraints}
Lecture 4 sql {basics  keys and constraints}Lecture 4 sql {basics  keys and constraints}
Lecture 4 sql {basics keys and constraints}Shubham Shukla
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteDatabase Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteAl-Mamun Sarkar
 
Null values, insert, delete and update in database
Null values, insert, delete and update in databaseNull values, insert, delete and update in database
Null values, insert, delete and update in databaseHemant Suthar
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorialamitabros
 
Ppt INFORMATIVE PRACTICES for class 11th chapter 14
Ppt INFORMATIVE PRACTICES for class 11th chapter 14Ppt INFORMATIVE PRACTICES for class 11th chapter 14
Ppt INFORMATIVE PRACTICES for class 11th chapter 14prashant0000
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsAshwin Dinoriya
 

La actualidad más candente (20)

06.01 sql select distinct
06.01 sql select distinct06.01 sql select distinct
06.01 sql select distinct
 
MS SQL Server 1
MS SQL Server 1MS SQL Server 1
MS SQL Server 1
 
SQL
SQLSQL
SQL
 
Database Management System 1
Database Management System 1Database Management System 1
Database Management System 1
 
Sql slid
Sql slidSql slid
Sql slid
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server ii
 
Sql
SqlSql
Sql
 
Sql
SqlSql
Sql
 
Lecture 3 sql {basics ddl commands}
Lecture 3 sql {basics  ddl commands}Lecture 3 sql {basics  ddl commands}
Lecture 3 sql {basics ddl commands}
 
Lecture 4 sql {basics keys and constraints}
Lecture 4 sql {basics  keys and constraints}Lecture 4 sql {basics  keys and constraints}
Lecture 4 sql {basics keys and constraints}
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
 
Sql basics v2
Sql basics v2Sql basics v2
Sql basics v2
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteDatabase Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and delete
 
Null values, insert, delete and update in database
Null values, insert, delete and update in databaseNull values, insert, delete and update in database
Null values, insert, delete and update in database
 
Sql reference from w3 schools
Sql reference from w3 schools Sql reference from w3 schools
Sql reference from w3 schools
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
Ppt INFORMATIVE PRACTICES for class 11th chapter 14
Ppt INFORMATIVE PRACTICES for class 11th chapter 14Ppt INFORMATIVE PRACTICES for class 11th chapter 14
Ppt INFORMATIVE PRACTICES for class 11th chapter 14
 
Select To Order By
Select  To  Order BySelect  To  Order By
Select To Order By
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
 

Similar a Mysql 120831075600-phpapp01

Similar a Mysql 120831075600-phpapp01 (20)

SQL
SQLSQL
SQL
 
dbms.pdf
dbms.pdfdbms.pdf
dbms.pdf
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
 
SQL
SQLSQL
SQL
 
1670595076250.pdf
1670595076250.pdf1670595076250.pdf
1670595076250.pdf
 
SQL 🌟🌟🔥.pdf
SQL 🌟🌟🔥.pdfSQL 🌟🌟🔥.pdf
SQL 🌟🌟🔥.pdf
 
SQL learning notes and all code.pdf
SQL learning notes and all code.pdfSQL learning notes and all code.pdf
SQL learning notes and all code.pdf
 
Cheat sheet SQL commands with examples and easy understanding
Cheat sheet SQL commands with examples and easy understandingCheat sheet SQL commands with examples and easy understanding
Cheat sheet SQL commands with examples and easy understanding
 
SQL : Structured Query Language
SQL : Structured Query LanguageSQL : Structured Query Language
SQL : Structured Query Language
 
Sql
SqlSql
Sql
 
Basic sql(oracle) queries
Basic sql(oracle) queriesBasic sql(oracle) queries
Basic sql(oracle) queries
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
Babitha2.mysql
Babitha2.mysqlBabitha2.mysql
Babitha2.mysql
 
Babitha2 Mysql
Babitha2 MysqlBabitha2 Mysql
Babitha2 Mysql
 
Sql commands
Sql commandsSql commands
Sql commands
 
Sql commands
Sql commandsSql commands
Sql commands
 
ADV PPT 2 LAB.pptx
ADV PPT 2 LAB.pptxADV PPT 2 LAB.pptx
ADV PPT 2 LAB.pptx
 
Prabu's sql quries
Prabu's sql quries Prabu's sql quries
Prabu's sql quries
 

Más de sagaroceanic11

Module 21 investigative reports
Module 21 investigative reportsModule 21 investigative reports
Module 21 investigative reportssagaroceanic11
 
Module 20 mobile forensics
Module 20 mobile forensicsModule 20 mobile forensics
Module 20 mobile forensicssagaroceanic11
 
Module 19 tracking emails and investigating email crimes
Module 19 tracking emails and investigating email crimesModule 19 tracking emails and investigating email crimes
Module 19 tracking emails and investigating email crimessagaroceanic11
 
Module 18 investigating web attacks
Module 18 investigating web attacksModule 18 investigating web attacks
Module 18 investigating web attackssagaroceanic11
 
Module 17 investigating wireless attacks
Module 17 investigating wireless attacksModule 17 investigating wireless attacks
Module 17 investigating wireless attackssagaroceanic11
 
Module 04 digital evidence
Module 04 digital evidenceModule 04 digital evidence
Module 04 digital evidencesagaroceanic11
 
Module 03 searching and seizing computers
Module 03 searching and seizing computersModule 03 searching and seizing computers
Module 03 searching and seizing computerssagaroceanic11
 
Module 01 computer forensics in todays world
Module 01 computer forensics in todays worldModule 01 computer forensics in todays world
Module 01 computer forensics in todays worldsagaroceanic11
 
Virtualisation with v mware
Virtualisation with v mwareVirtualisation with v mware
Virtualisation with v mwaresagaroceanic11
 
Virtualisation overview
Virtualisation overviewVirtualisation overview
Virtualisation overviewsagaroceanic11
 
Introduction to virtualisation
Introduction to virtualisationIntroduction to virtualisation
Introduction to virtualisationsagaroceanic11
 
2 the service lifecycle
2 the service lifecycle2 the service lifecycle
2 the service lifecyclesagaroceanic11
 
1 introduction to itil v[1].3
1 introduction to itil v[1].31 introduction to itil v[1].3
1 introduction to itil v[1].3sagaroceanic11
 
Visual studio 2008 overview
Visual studio 2008 overviewVisual studio 2008 overview
Visual studio 2008 overviewsagaroceanic11
 

Más de sagaroceanic11 (20)

Module 21 investigative reports
Module 21 investigative reportsModule 21 investigative reports
Module 21 investigative reports
 
Module 20 mobile forensics
Module 20 mobile forensicsModule 20 mobile forensics
Module 20 mobile forensics
 
Module 19 tracking emails and investigating email crimes
Module 19 tracking emails and investigating email crimesModule 19 tracking emails and investigating email crimes
Module 19 tracking emails and investigating email crimes
 
Module 18 investigating web attacks
Module 18 investigating web attacksModule 18 investigating web attacks
Module 18 investigating web attacks
 
Module 17 investigating wireless attacks
Module 17 investigating wireless attacksModule 17 investigating wireless attacks
Module 17 investigating wireless attacks
 
Module 04 digital evidence
Module 04 digital evidenceModule 04 digital evidence
Module 04 digital evidence
 
Module 03 searching and seizing computers
Module 03 searching and seizing computersModule 03 searching and seizing computers
Module 03 searching and seizing computers
 
Module 01 computer forensics in todays world
Module 01 computer forensics in todays worldModule 01 computer forensics in todays world
Module 01 computer forensics in todays world
 
Virtualisation with v mware
Virtualisation with v mwareVirtualisation with v mware
Virtualisation with v mware
 
Virtualisation overview
Virtualisation overviewVirtualisation overview
Virtualisation overview
 
Virtualisation basics
Virtualisation basicsVirtualisation basics
Virtualisation basics
 
Introduction to virtualisation
Introduction to virtualisationIntroduction to virtualisation
Introduction to virtualisation
 
6 service operation
6 service operation6 service operation
6 service operation
 
5 service transition
5 service transition5 service transition
5 service transition
 
4 service design
4 service design4 service design
4 service design
 
3 service strategy
3 service strategy3 service strategy
3 service strategy
 
2 the service lifecycle
2 the service lifecycle2 the service lifecycle
2 the service lifecycle
 
1 introduction to itil v[1].3
1 introduction to itil v[1].31 introduction to itil v[1].3
1 introduction to itil v[1].3
 
Visual studio 2008 overview
Visual studio 2008 overviewVisual studio 2008 overview
Visual studio 2008 overview
 
Vb introduction.
Vb introduction.Vb introduction.
Vb introduction.
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Último (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

Mysql 120831075600-phpapp01

  • 2.  The Data Definition Language (DDL) part of SQL permits database tables to be created or deleted. We can also define indexes (keys), specify links between tables, and impose constraints between database tables.  CREATE TABLE - creates a new database table  ALTER TABLE - alters (changes) a database table  DROP TABLE - deletes a database
  • 3.  SQL (Structured Query Language) is a syntax for executing queries. But the SQL language also includes a syntax to update, insert, and delete records.  SELECT - extracts data from a database table  UPDATE - updates data in a database table  DELETE - deletes data from a database table  INSERT INTO - inserts new data into a database table
  • 4.  To create a database:  SYNTAX  CREATE DATABASE database_name ;  EXAMPLE  CREATE DATABASE s2i;  To activate the created database:  SYNTAX  USE DATABASE_NAME;
  • 5.  SYNTAX  CREATE TABLE table_name(column_name1 data_type,column_name2 data_type,.......) ;
  • 6. Data Type Description integer(size) int(size) smallint(size) tinyint(size) Hold integers only. The maximum number of digits are specified in parenthesis. decimal(size,d) numeric(size,d ) Hold numbers with fractions. The maximum number of digits are specified in "size". The maximum number of digits to the right of the decimal is specified in "d". char(size) Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis. varchar(size) Holds a variable length string (can contain letters, numbers, and special characters). The maximum size is specified in parenthesis. date(yyyymmd d) Holds a date
  • 7.  The INSERT INTO statement is used to insert new rows into a table.  SYNTAX  INSERT INTO table_name VALUES (value1, value2,....) ;  INSERT INTO table_name (column1, column2,...)VALUES (value1, value2,....) ;
  • 8.  The UPDATE statement is used to modify the data in a table.  SYNTAX  UPDATE table_name SET column1= new_value WHERE Old_column1=old_value;
  • 9.  The ALTER TABLE statement is used to add or drop columns in an existing table.  SYNTAX  ALTER TABLE table_name ADD column_name data_type;
  • 10.  The DELETE statement is used to delete rows in a table.  Syntax  DELETE FROM table_name WHERE column_name = some_value;
  • 11.  Delete All Rows  DELETE FROM table_name;  OR  DELETE * FROM table_name;  OR  TRUNCATE TABLE table_name;
  • 12.  To delete a table  DROP TABLE table_name;  To delete a database  DROP DATABASE database_name;  To delete the column in table  ALTER TABLE table_name DROP COLUMN column_name;
  • 13.  The SELECT statement is used to select data from a table. The tabular result is stored in a result table (called the result-set).  Select a table fully  Syntax  SELECT * FROM Persons;
  • 14.  SELECT A COLUMN  Select column_name from table_name;  SELECT A ROW  Select*from table_name where column_name=‘value’;
  • 15.  All values stored in mysql is in array formate.  $var1=mysql_query(“select*from table_name”, $connection_name);  While($var=mysql_fetch_array($var1))  {  Echo “<br/>”;  Echo $var[‘column_name’];  }
  • 16.  The LIKE & UNLIKE condition is used to specify a search for a pattern in a column.  Syntax  SELECT column FROM table_name WHERE column_name LIKE pattern;  SELECT column FROM table_name WHERE column_name UNLIKE pattern;
  • 17.  EXAMPLES  SELECT * FROM table_name WHERE column_name LIKE 'O%‘;  SELECT * FROM table_name WHERE column_name LIKE '%a‘;  SELECT * FROM table_name WHERE column_name LIKE '%la%‘;
  • 18.  The AND & OR operators are used to filter records based on more than one condition.  The AND operator displays a record if both the first condition and the second condition is true.  The OR operator displays a record if either the first condition or the second condition is true.
  • 19.  SELECT * FROM table_name WHERE column1=‘value' AND column2=‘value‘;  SELECT * FROM table_name WHERE column1=‘value1' OR column1=‘value2‘;  SELECT * FROM table_name WHERE column1=‘value' AND (column2=‘value1' OR column2=‘value2‘);
  • 20.  The ORDER BY keyword is used to sort the result-set by a specified column.  The ORDER BY keyword sort the records in ascending order by default.  If you want to sort the records in a descending order, you can use the DESC keyword.
  • 21.  SELECT column_name(s) FROM table_name ORDER BY column_name(s) ASC|DESC;  SELECT * FROM table_name ORDER BY column_name;  SELECT * FROM table_name ORDER BY column_name DESC;
  • 22.  Auto-increment allows a unique number to be generated when a new record is inserted into a table.  CREATE TABLE Persons ( Id int (5) AUTO_INCREMENT)  ALTER TABLE Persons AUTO_INCREMENT=100 ;
  • 23.  The TOP clause is used to specify the number of records to return.  The TOP clause can be very useful on large tables with thousands of records. Returning a large number of records can impact on performance.  Note: Not all database systems support the TOP clause.
  • 24.  SELECT column_name(s) FROM table_name LIMIT number;  SELECT TOP 2 * FROM table_name;  SELECT TOP 50 PERCENT * FROM table_name;
  • 25.  With SQL, aliases can be used for column names and table names.  SELECT column AS column_alias FROM table;  EXAMPLES: SELECT LastName AS Family, FirstName AS NameFROM Persons;  SELECT column FROM table AS table_alias;  EXAMPLE: SELECT LastName, FROM Persons AS Employees;
  • 26.  The IN operator allows you to specify multiple values in a WHERE clause.  SELECT column_name(s) FROM table_name WHERE column_name IN (value1,value2,...);  SELECT * FROM table_name WHERE column IN (‘value1',‘value2');
  • 27.  The BETWEEN operator selects a range of data between two values. The values can be numbers, text, or dates.  SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2;  SELECT column_name(s) FROM table_name WHERE column_name NOTBETWEEN value1 AND value2;
  • 28.  To select only DIFFERENT values from the column named  SYNTAX  SELECT DISTINCT Company FROM Orders;
  • 29.  Constraints are used to limit the type of data that can go into a table.  Constraints can be specified when a table is created (with the CREATE TABLE statement) or after the table is created (with the ALTER TABLE statement).  NOT NULL  UNIQUE  CHECK  PRIMARY KEY  FOREIGN KEY  DEFAULT
  • 30.  The NOT NULL constraint enforces a column to NOT accept NULL values.  CREATE TABLE Persons ( P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255) )
  • 31.  The UNIQUE constraint uniquely identifies each record in a database table.  CREATE TABLE Persons ( P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255), UNIQUE (P_Id) );  Alter table table_name ADD UNIQUE (ID);
  • 32.  The PRIMARY KEY constraint uniquely identifies each record in a database table.  Primary keys must contain unique values.  A primary key column cannot contain NULL values  CREATE TABLE Persons ( P_Id int NOT NULL, LastName varchar(255) NOT NULL, PRIMARY KEY (P_Id) )  ALTER TABLE Persons ADD PRIMARY KEY (P_Id)
  • 33.  A FOREIGN KEY in one table points to a PRIMARY KEY in another table.  CREATE TABLE Orders ( O_Id int NOT NULL, OrderNo int NOT NULL, P_Id int, PRIMARY KEY (P_Id), FOREIGN KEY (O_Id) REFERENCES Persons(P_Id) )  ALTER TABLE Orders ADD FOREIGN KEY (O_Id) REFERENCES Persons(P_Id)
  • 34.  The CHECK constraint is used to limit the value range that can be placed in a column.  CREATE TABLE Persons ( P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255), CHECK (P_Id>0) )  ALTER TABLE Persons ADD CHECK (P_Id>0)
  • 35.  The DEFAULT constraint is used to insert a default value into a column.  CREATE TABLE Persons ( P_Id int NOT NULL, City varchar(255) DEFAULT 'Sandnes' )  ALTER TABLE Persons WHERE City SET DEFAULT 'SANDNES'
  • 36.  An index can be created in a table to find data more quickly and efficiently.  CREATE INDEX index_name ON table_name (column_name);  CREATE UNIQUE INDEX index_name ON table_name (column_name);  Drop INDEX index_name FROM TABLE_NAME;
  • 37.  The JOIN keyword is used in an SQL statement to query data from two or more tables, based on a relationship between certain columns in these tables.  Different SQL JOINS  INNER JOIN  OUTER JOIN  FULL JOIN
  • 38.  The INNER JOIN keyword return rows when there is at least one match in both tables.  SELECT column_name(s) FROM table_name1 INNER JOIN table_name2 ON table_name1.column_name=table_name2.col umn_name
  • 39.  The LEFT JOIN keyword returns all rows from the left table (table_name1), even if there are no matches in the right table (table_name2).  SELECT column_name(s) FROM table_name1 LEFT JOIN table_name2 ON table_name1.column_name=table_name2.col umn_name
  • 40.  The RIGHT JOIN keyword Return all rows from the right table (table_name2), even if there are no matches in the left table (table_name1).  SELECT column_name(s) FROM table_name1 RIGHT JOIN table_name2 ON table_name1.column_name=table_name2.col umn_name
  • 41.  The FULL JOIN keyword return rows when there is a match in one of the tables.  SELECT column_name(s) FROM table_name1 FULL JOIN table_name2 ON table_name1.column_name=table_name2.col umn_name
  • 42. SQL aggregate functions return a single value, calculated from values in a column.  AVG() - Returns the average value  COUNT() - Returns the number of rows  FIRST() - Returns the first value  LAST() - Returns the last value  MAX() - Returns the largest value  MIN() - Returns the smallest value  SUM() - Returns the sum
  • 43. SQL scalar functions return a single value, based on the input value.  UCASE() - Converts a field to upper case  LCASE() - Converts a field to lower case  MID() - Extract characters from a text field  LEN() - Returns the length of a text field  ROUND() - Rounds a numeric field to the number of decimals specified  NOW() - Returns the current system date and time  FORMAT() - Formats how a field is to be displayed
  • 44.  GROUP BY... was added to SQL because aggregate functions (like SUM) return the aggregate of all column values every time they are called, and without the GROUP BY function it was impossible to find the sum for each individual group of column values.
  • 45.  SELECT column, SUM(column) FROM table GROUP BY column;  EXAMPLE: SELECT Company, SUM(Amount) FROM Sales;  SELECT Company, SUM(Amount) FROM Sales GROUP BY Company;  SELECT column, SUM(column) FROM table GROUP BY column HAVING SUM(column) condition value;
  • 46. Statement Syntax AND / OR SELECT column_name(s) FROM table_name WHERE condition AND|OR condition ALTER TABLE (add column)*// ALTER TABLE table_name ADD column_name datatype ALTER TABLE (drop column) ALTER TABLE table_name DROP COLUMN column_name AS (alias for column) SELECT column_name AS column_alias FROM table_name AS (alias for table) SELECT column_name FROM table_name AS table_alias BETWEEN SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2 CREATE DATABASE CREATE DATABASE database_name CREATE INDEX CREATE INDEX index_name ON table_name (column_name)
  • 47. CREATE TABLE CREATE TABLE table_name ( column_name1 data_type, column_name2 data_type, ....... ) CREATE UNIQUE INDEX CREATE UNIQUE INDEX index_name ON table_name (column_name) CREATE VIEW CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition DELETE FROM DELETE FROM table_name (Note: Deletes the entire table!!) or DELETE FROM table_name WHERE condition DROP DATABASE DROP DATABASE database_name DROP INDEX DROP INDEX table_name.index_name DROP TABLE DROP TABLE table_name
  • 48. GROUP BY SELECT column_name1,SUM(column_name2) FROM table_name GROUP BY column_name1 HAVING SELECT column_name1,SUM(column_name2) FROM table_name GROUP BY column_name1 HAVING SUM(column_name2) condition value IN SELECT column_name(s) FROM table_name WHERE column_name IN (value1,value2,..) INSERT INTO INSERT INTO table_name VALUES (value1, value2,....) LIKE SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern
  • 49. ORDER BY SELECT column_name(s) FROM table_name ORDER BY column_name [ASC|DESC] SELECT SELECT column_name(s) FROM table_name SELECT * SELECT * FROM table_name SELECT DISTINCT SELECT DISTINCT column_name(s) FROM table_name SELECT INTO (used to create backup copies of tables) SELECT * INTO new_table_name FROM original_table_name or SELECT column_name(s) INTO new_table_name FROM original_table_name
  • 50. SELECT INTO (used to create backup copies of tables) SELECT * INTO new_table_name FROM original_table_name or SELECT column_name(s) INTO new_table_name FROM original_table_name TRUNCATE TABLE (deletes only the data inside the table) TRUNCATE TABLE table_name UPDATE UPDATE table_name SET column_name=new_value [, column_name=new_value] WHERE column_name=some_value WHERE SELECT column_name(s) FROM table_name WHERE condition