SlideShare a Scribd company logo
1 of 37
Informatics
PracticesHoliday Homework!!!!!!!!!!
Name: Farheen Abdul Hameed.
Class: IX-B
To Create A Database:
Syntax:
Create Database {Database Name};
Purpose:
The create database query allows us to create a
database to server as a container for the tables in that
database
Query:
Create Database STUDENT;
To Use A Database:
Syntax:
{Database name};
Purpose:
Creating a database is not enough, before you create a
table you must first open the database using the Use
Database query.
Query:
Use Database STUDENT;
DROP DATABASE
Syntax:
DROP DATABASE database name;
Purpose:
If there is any unwanted database the Drop Database
query is used to remove it.
Query:
DROP DATABASE test DB;
To Create A Tables:
Syntax:
CREATE TABLE < Table name > (< Column name 1
> < Data type 1 >, < Column name 2 > < Data type 2
> ……., < Column name N > < Data type N >)
Purpose: Once you create a table you can store data in
it in a structured way using columns and rows.
Query:
CREATE TABLE < Table name > (< Column name 1 > <
Data type 1 >, < Column name 2 > < Data type 2 > …….,
< Column name N > < Data type N >);
OUTPUT:
Table: Student profile
S.no Register no Name Marks
1 2045 Hassan 67
2 2546 Talha 99
To Insert Into A Table:
Syntax:
Insert into { table name} Values ({ value1, value2,
valueN}) ;
Purpose:
It is used to added data in the columns of a tables.
Query:
Insert into STUDENT Values ( 1, 2, “Jane”, 2, 3,
“Sam”);
OUTPUT:
STUDENT
S.No Roll. No Name
1 2 Jane
2 3 Sam
Viewing Structure Of A Table:
Syntax:
Describe {table name}; / Desc { table name};
Purpose:
To view the structure of a table
Query:
Describe STUDENT; / Desc STUDENT;
OUTPUT:
STUDENT
S.No Roll. No Name
1 2 Jane
2 3 Sam
Retrieving a Column From a Table:
Syntax:
Select {column name} FROM {tablename} ;
Purpose:
This syntax is used to extract only a specific column
from a table.
Query:
Select Name FROM STUDENT;
OUTPUT:
STUDENT
Name
Jane
Sam
Changing The Order Of Display Of
Column:
Syntax:
Select {Column1}, {Column2}, {Column3} FROM {Table
name};
Purpose:
Allows for the rearrange of the structure of a table.
Query:
Select S. No, Name, Roll. No FROM STUDENT;
OUTPUT:
STUDENT
Changing structure of a table
a) To add a column
Syntax:
ALTER TABLE < Table name > ADD < Column name >
[ Data type];
S.No Name Roll. No
1 Jane 2
2 Sam 3
Purpose:
To add a column in a table, use the following
syntax:
Query:
ALTER TABLE Student profile ADD DOB Date ;
OUTPUT:
S.no Register
no
Name Marks DOB
1 4520 Hassan 23 20-05-
2000
2 5022 Talha 45 21-02-
2000
b)To drop a table
Syntax:
ALTER TABLE < Table name > DROP < Column name
> [ Data type];
Purpose:
The DROP TABLE statement is used to drop an
existing table in a database.
Query:
ALTER TABLE Student profile DROP DOB Date;
OUTPUT:
S.no Register no Name Marks
1 4020 Hassan 97
2 5204 Talha 86
c) To modify a column name
Syntax:
ALTER TABLE < Table name > MODIFY < Column
name > < New _ Column name >;
Purpose:
To modify a column in an existing table, the SQL
ALTER TABLE syntax is:
Query:
ALTER TABLE Student profile MODIFY Register no
Reg.no ;
OUTPUT:
S.no Reg. no Name Marks
1 8572 Hassan 94
2 7857 Talha 86
Retrieving information with SELECT
statement
I. Retrieving single column
Syntax:
SELECT < Column name > FROM < Table name >;
Purpose:
The SELECT statement is used to select data from a
database.
The data returned is stored in a result table, called the
result-set.
Query:
SELECT Name FROM Student profile;
OUTPUT:
Student profile
Name
Hassan
Talha
II. Retrieving multiple columns
Syntax:
SELECT < Column name 1 >, < Column name 2 >
FROM < Table name >;
Purpose:
The SELECT statement is used to select data from
a database.
The data returned is stored in a result table, called
the result-set.
Query:
SELECT Name , Marks FROM Student profile;
OUTPUT:
Student profile
Name Marks
Hassan 95
Talha 90
Retrieving all columns
Syntax:
SELECT * FROM < Table name >;
Query:
SELECT * FROM Student profile ;
OUTPUT:
Student profile
S.no Reg. no Name Marks
1 1123 Hassan 85
2 1234 Talha 87
Retrieving data from all rows
Using arithmetic operators with SELECT
Query:
SELECT Marks + 5 FROM Student profile;
OUTPUT:
Student profile
Marks + 5
90
92
Query:
SELECT Marks – 5 FROM Student profile;
OUTPUT:
Student profile
Marks - 5
80
82
Running a query without a table
SELECT 55*2 + 1;
Result : 111
Using column alias
Syntax:
SELECT < Column name > AS < “ New Column name “ >
FROM < Table name >;
Purpose:
SQL aliases are used to give a table, or a column in
a table, a temporary name.
Aliases are often used to make column names
more readable.
An alias only exists for the duration of the query.
Query:
SELECT Reg.no AS “ Register no “ FROM Student profile ;
OUTPUT:
Student profile
Register no
5243
1444
Putting text in query output
Query:
SELECT S.no , Reg.no , Name , ‘ Class 11B ‘ , Marks FROM
Student profile;
OUTPUT:
Student profile
S.no Reg. no Name Class 11B Marks
1 2564 Hassan Class 11B 97
2 1564 Talha Class 11B 90
Retrieving Specific Rows - ( Where Class):
Syntax:
Select * FROM Student WHERE { Condition};
Purpose:
This syntax is used to extract only specific rows from a
table using logical and relational operators.
Query:
SELECT * FROM Customers
WHERE Country='Mexico';
OUTPUT:
Relational operators
Syntax:
SELECT * FROM < Table name > WHERE < Column name
> < Condition >;
Query:
SELECT * FROM Student profile WHERE Marks = 85;
OUTPUT:
Student profile
S.no Reg. no Name Marks
1 7928 Hassan 85
Query:
SELECT * FROM Student profile WHERE Name = ‘ Talha ‘ ;
OUTPUT:
Student profile
Logical operators
Query:
SELECT * FROM Student profile WHERE Marks > 85 AND
Marks < 90;
OUTPUT:
Student profile
S.no Reg.no Name Marks
2 7629 Talha 87
S.no Reg.no Name Marks
2 1512 Talha 87
Condition based on range
Syntax:
SELECT * FROM < Table name > WHERE < Column name
> BETWEEN < Condition >;
Query:
SELECT * FROM Student profile WHERE Marks BETWEEN
80 AND 90 ;
OUTPUT:
Student profile
S.no Reg. no Name Marks
1 7658 Hassan 85
2 1572 Talha 87
Condition based on list
Query:
SELECT * FROM Student profile WHERE Marks IN (
85,86,87 );
OUTPUT:
Student profile
S.no Reg. no Name Marks
1 2316 Hassan 85
2 1210 Talha 87
Condition based on pattern matches
Syntax:
SELECT * FROM < Table name > WHERE < Column
name > LIKE PATTERN < Condition>;
Query:
SELECT * FROM Student profile WHERE Name LIKE ‘
A% ‘ ;
OUTPUT:
Student profile
S.no Reg. no Name Marks
1 3535 Hassan 85
CREATE TABLE
Syntax:
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
....
);
Purpose:
The CREATE TABLE statement is used to create a
new table in a database.
Query:
CREATE TABLE Persons
(
Person ID int,
LastName varchar (255),
First Name varchar (255),
Address varchar (255),
City varchar (255)
);
Inserting into a Table
Syntax:
INSERT INTO < Table name > VALUES ( < Value 1 > , <
Value 2 > , ……,< Value N > );
Purpose:
The INSERT INTO statement is used to insert new
records in a table.
Query:
INSERT INTO Student profile VALUES ( 1 , 2052 , ‘
Hassan ‘ , 85 );
INSERT INTO Student profile VALUES ( 2 , 2053 , ‘
Talha ‘ , 87 );
OUTPUT:
Table: Student profile
S.no Register no Name Marks
1 2052 Hassan 85
2 2053 Talha 87
Select all the data
Syntax:
SELECT * FROM < Table name >;
Purpose:
The data returned is stored in a result table, called
the result-set.
Query:
SELECT * FROM Student profile ;
OUTPUT:
Table: Student profile
S.no Register no Name Marks
1 2052 Hassan 85
2 2053 Talha 87
Knowing the current database
Syntax:
Show database () / Database ();
Purpose:
SHOW DATABASES lists the databases on the Maria DB
server host. SHOW SCHEMAS is a synonym for SHOW
DATABASES.
Query:
Show database (Student profile)/Database (Student
profile)
OUTPUT:
Table: Student profile
S.no Register no Name Marks
1 2052 Hassan 85
2 2053 Talha 87
Updating Records
Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Purpose:
The UPDATE statement is used to modify the
existing records in a table.
Query:
UPDATE Customers
SET Contact Name = 'Alfred Schmidt', City= 'Frankfurt'
WHERE Customer ID = 1;
OUTPUT:
Deleting Records
Syntax:
DELETE FROM table_name
WHERE condition;
Purpose:
The DELETE statement is used to delete existing
records in a table.
Query:
DELETE FROM Customers
WHERE Customer Name='Alfred’s Futterkiste';
OUTPUT:
Drop a Table
Syntax:
DROP TABLE table_name;
Purpose:
The DROP TABLE statement is used to drop an
existing table in a database.
Query:
DROP TABLE Shippers;
SELECT Column
Syntax:
SELECT * FROM _name;
Purpose:
The SELECT statement is used to select data from
a database.
The data returned is stored in a result table, called
the result-set.
Query:
SELECT * FROM Customers;
OUTPUT:
The SQL SELECT DISTINCT
Statement
Syntax:
SELECT DISTINCT <column1, column2, ...>
FROM table_name;
Purpose:
The SELECT DISTINCT statement is used to return
only distinct (different) values.
Query:
SELECT DISTINCT Country FROM Customers;
OUTPUT:
The SQL WHERE Clause
WHERE
Syntax:
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Purpose:
The WHERE clause is used to filter records.
The WHERE clause is used to extract only those
records that fulfill a specified condition.
Query:
SELECT * FROM Customers
WHERE Country='Mexico';
OUTPUT:
The SQL AND, OR and NOT
Operators
AND
Syntax:
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition
3 ...;
Purpose:
The AND operator displays a record if all the
conditions separated by AND is TRUE.
Query:
SELECT * FROM Customers
WHERE Country='Germany' AND City='Berlin';
OR
Syntax:
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3
...;
Purpose:
The OR operator displays a record if any of the
conditions separated by OR is TRUE.
Query:
SELECT * FROM Customers
WHERE City='Berlin' OR City='Munched';
NOT
Syntax:
SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;
Purpose:
The NOT operator displays a record if the
condition(s) is NOT TRUE.
Query:
SELECT * FROM Customers
WHERE NOT Country='Germany';
OUTPUT:
The SQL ORDER BY Keyword
Syntax:
SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;
Purpose:
The ORDER BY keyword is used to sort the result-
set in ascending or descending order.
The ORDER BY keyword sorts the records in
ascending order by default. To sort the records in
descending order, use the DESC keyword.
Query:
SELECT * FROM Customers
ORDER BY Country ASC, Customer Name DESC;
OUTPUT:
MIN ()
Syntax:
SELECT MIN(column_name)
FROM table_name
WHERE condition;
Purpose:
The MIN() function returns the smallest value of
the selected column.
Query:
SELECT MIN(Price) AS Smallest Price
FROM Products;
OUTPUT:
MAX ()
Syntax:
SELECT MAX(column_name)
FROM table_name
WHERE condition;
Purpose:
The MAX () function returns the largest value of
the selected column.
Query:
SELECT MAX(Price) AS Largest Price
FROM Products;
OUTPUT:
LIKE
Syntax:
SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;
Purpose:
The LIKE operator is used in a WHERE clause to
search for a specified pattern in a column.
There are two wildcards used in conjunction with
the LIKE operator:
 % - The percent sign represents zero, one, or
multiple characters
 _ - The underscore represents a single
character
Query:
SELECT * FROM Customers
WHERE Customer Name LIKE 'a%';
OUTPUT:
BETWEEN
Syntax:
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
Purpose:
The BETWEEN operator selects values within a
given range. The values can be numbers, text, or
dates.
The BETWEEN operator is inclusive: begin and end
values are included.
Query:
SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20;
OUTPUT:
SELECT INTO
Syntax:
Copy all columns into a new table:
SELECT *
INTO new table [IN external dB]
FROM old table
WHERE condition;
Purpose:
The SELECT INTO statement copies data from one
table into a new table.
Query:
SELECT * INTO Customers Germany
FROM Customers
WHERE Country = 'Germany';
INSERT INTO SELECT
Syntax:
Copy all columns from one table to another
table:
INSERT INTO table2
SELECT * FROM table1
WHERE condition;
Purpose:
The INSERT INTO SELECT statement copies data
from one table and inserts it into another table.
 INSERT INTO SELECT requires that data types
in source and target tables match
 The existing records in the target table are
unaffected
Query:
INSERT INTO Customers (Customer Name, Contact
Name, Address, City, PostalCode,Country)
SELECT Supplier Name, Contact Name, Address,
City, Postal Code, Country FROM Suppliers;
OUTPUT:
GROUP BY
Syntax
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);
Query
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
ORDER BY COUNT(CustomerID) DESC;
DROP TABLE
Syntax:
DROP TABLE table_name;
Purpose:
The DROP TABLE statement is used to drop an
existing table in a database.
Query:
DROP TABLE Shippers;
OUTPUT:
SQL Arithmetic Operators
SQL Bitwise Operators
SQL Comparison Operators
SQL Compound Operators
SQL Logical Operators
SQL General Data Types
SQL Data Type Quick Reference
Date types:
SQL Quick Reference
Farheen abdul hameed ip project (MY SQL);
Farheen abdul hameed ip project (MY SQL);

More Related Content

What's hot (19)

Lab
LabLab
Lab
 
SQL
SQLSQL
SQL
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statements
 
Oracle: DDL
Oracle: DDLOracle: DDL
Oracle: DDL
 
STRUCTURED QUERY LANGUAGE
STRUCTURED QUERY LANGUAGESTRUCTURED QUERY LANGUAGE
STRUCTURED QUERY LANGUAGE
 
SQL
SQLSQL
SQL
 
Sql coding-standard-sqlserver
Sql coding-standard-sqlserverSql coding-standard-sqlserver
Sql coding-standard-sqlserver
 
Sql commands
Sql commandsSql commands
Sql commands
 
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
SqlSql
Sql
 
Database Overview
Database OverviewDatabase Overview
Database Overview
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)
 
ADBMS Unit-II c
ADBMS Unit-II cADBMS Unit-II c
ADBMS Unit-II c
 
Database Management System 1
Database Management System 1Database Management System 1
Database Management System 1
 
SQL
SQLSQL
SQL
 
MY SQL
MY SQLMY SQL
MY SQL
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
 
Rdbms day3
Rdbms day3Rdbms day3
Rdbms day3
 
Sql reference from w3 schools
Sql reference from w3 schools Sql reference from w3 schools
Sql reference from w3 schools
 

Similar to Farheen abdul hameed ip project (MY SQL);

Similar to Farheen abdul hameed ip project (MY SQL); (20)

My sql Syntax
My sql SyntaxMy sql Syntax
My sql Syntax
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
SQL : Structured Query Language
SQL : Structured Query LanguageSQL : Structured Query Language
SQL : Structured Query Language
 
Its about a sql topic for basic structured query language
Its about a sql topic for basic structured query languageIts about a sql topic for basic structured query language
Its about a sql topic for basic structured query language
 
Sql Basics | Edureka
Sql Basics | EdurekaSql Basics | Edureka
Sql Basics | Edureka
 
COMPUTERS SQL
COMPUTERS SQL COMPUTERS SQL
COMPUTERS SQL
 
01 basic orders
01   basic orders01   basic orders
01 basic orders
 
Sql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.pptSql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.ppt
 
unit-5 sql notes.docx
unit-5 sql notes.docxunit-5 sql notes.docx
unit-5 sql notes.docx
 
DBMS.pdf
DBMS.pdfDBMS.pdf
DBMS.pdf
 
Les10 Creating And Managing Tables
Les10 Creating And Managing TablesLes10 Creating And Managing Tables
Les10 Creating And Managing Tables
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
 
Creating a database
Creating a databaseCreating a database
Creating a database
 
SQL- MOST IMPORTANT CONCEPTS
SQL- MOST IMPORTANT CONCEPTSSQL- MOST IMPORTANT CONCEPTS
SQL- MOST IMPORTANT CONCEPTS
 
Sql 
statements , functions & joins
Sql 
statements , functions  &  joinsSql 
statements , functions  &  joins
Sql 
statements , functions & joins
 
Structured Query Language(SQL)
Structured Query Language(SQL)Structured Query Language(SQL)
Structured Query Language(SQL)
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 

Recently uploaded

SD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptxSD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptxjanettecruzeiro1
 
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...Suhani Kapoor
 
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制didi bibo
 
Captivating Charm: Exploring Marseille's Hillside Villas with Our 3D Architec...
Captivating Charm: Exploring Marseille's Hillside Villas with Our 3D Architec...Captivating Charm: Exploring Marseille's Hillside Villas with Our 3D Architec...
Captivating Charm: Exploring Marseille's Hillside Villas with Our 3D Architec...Yantram Animation Studio Corporation
 
VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...
VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...
VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...Suhani Kapoor
 
The_Canvas_of_Creative_Mastery_Newsletter_April_2024_Version.pdf
The_Canvas_of_Creative_Mastery_Newsletter_April_2024_Version.pdfThe_Canvas_of_Creative_Mastery_Newsletter_April_2024_Version.pdf
The_Canvas_of_Creative_Mastery_Newsletter_April_2024_Version.pdfAmirYakdi
 
Cheap Rate Call girls Kalkaji 9205541914 shot 1500 night
Cheap Rate Call girls Kalkaji 9205541914 shot 1500 nightCheap Rate Call girls Kalkaji 9205541914 shot 1500 night
Cheap Rate Call girls Kalkaji 9205541914 shot 1500 nightDelhi Call girls
 
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...babafaisel
 
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...Pooja Nehwal
 
Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...
Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...
Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...ankitnayak356677
 
ARt app | UX Case Study
ARt app | UX Case StudyARt app | UX Case Study
ARt app | UX Case StudySophia Viganò
 
The history of music videos a level presentation
The history of music videos a level presentationThe history of music videos a level presentation
The history of music videos a level presentationamedia6
 
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 nightCheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 nightDelhi Call girls
 
Kindergarten Assessment Questions Via LessonUp
Kindergarten Assessment Questions Via LessonUpKindergarten Assessment Questions Via LessonUp
Kindergarten Assessment Questions Via LessonUpmainac1
 
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Servicejennyeacort
 
WAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsWAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsCharles Obaleagbon
 
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai DouxDubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Douxkojalkojal131
 
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...Suhani Kapoor
 

Recently uploaded (20)

SD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptxSD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptx
 
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
 
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
 
Captivating Charm: Exploring Marseille's Hillside Villas with Our 3D Architec...
Captivating Charm: Exploring Marseille's Hillside Villas with Our 3D Architec...Captivating Charm: Exploring Marseille's Hillside Villas with Our 3D Architec...
Captivating Charm: Exploring Marseille's Hillside Villas with Our 3D Architec...
 
VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...
VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...
VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...
 
The_Canvas_of_Creative_Mastery_Newsletter_April_2024_Version.pdf
The_Canvas_of_Creative_Mastery_Newsletter_April_2024_Version.pdfThe_Canvas_of_Creative_Mastery_Newsletter_April_2024_Version.pdf
The_Canvas_of_Creative_Mastery_Newsletter_April_2024_Version.pdf
 
Cheap Rate Call girls Kalkaji 9205541914 shot 1500 night
Cheap Rate Call girls Kalkaji 9205541914 shot 1500 nightCheap Rate Call girls Kalkaji 9205541914 shot 1500 night
Cheap Rate Call girls Kalkaji 9205541914 shot 1500 night
 
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
 
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance VVIP 🍎 SER...
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SER...Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SER...
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance VVIP 🍎 SER...
 
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...
 
Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...
Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...
Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...
 
ARt app | UX Case Study
ARt app | UX Case StudyARt app | UX Case Study
ARt app | UX Case Study
 
The history of music videos a level presentation
The history of music videos a level presentationThe history of music videos a level presentation
The history of music videos a level presentation
 
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
 
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 nightCheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
 
Kindergarten Assessment Questions Via LessonUp
Kindergarten Assessment Questions Via LessonUpKindergarten Assessment Questions Via LessonUp
Kindergarten Assessment Questions Via LessonUp
 
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
 
WAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsWAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past Questions
 
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai DouxDubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
 
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
 

Farheen abdul hameed ip project (MY SQL);

  • 2. To Create A Database: Syntax: Create Database {Database Name}; Purpose: The create database query allows us to create a database to server as a container for the tables in that database Query: Create Database STUDENT; To Use A Database: Syntax: {Database name}; Purpose: Creating a database is not enough, before you create a table you must first open the database using the Use Database query. Query: Use Database STUDENT; DROP DATABASE Syntax: DROP DATABASE database name; Purpose: If there is any unwanted database the Drop Database query is used to remove it.
  • 3. Query: DROP DATABASE test DB; To Create A Tables: Syntax: CREATE TABLE < Table name > (< Column name 1 > < Data type 1 >, < Column name 2 > < Data type 2 > ……., < Column name N > < Data type N >) Purpose: Once you create a table you can store data in it in a structured way using columns and rows. Query: CREATE TABLE < Table name > (< Column name 1 > < Data type 1 >, < Column name 2 > < Data type 2 > ……., < Column name N > < Data type N >); OUTPUT: Table: Student profile S.no Register no Name Marks 1 2045 Hassan 67 2 2546 Talha 99 To Insert Into A Table: Syntax: Insert into { table name} Values ({ value1, value2, valueN}) ; Purpose: It is used to added data in the columns of a tables. Query:
  • 4. Insert into STUDENT Values ( 1, 2, “Jane”, 2, 3, “Sam”); OUTPUT: STUDENT S.No Roll. No Name 1 2 Jane 2 3 Sam Viewing Structure Of A Table: Syntax: Describe {table name}; / Desc { table name}; Purpose: To view the structure of a table Query: Describe STUDENT; / Desc STUDENT; OUTPUT: STUDENT S.No Roll. No Name 1 2 Jane 2 3 Sam Retrieving a Column From a Table: Syntax: Select {column name} FROM {tablename} ; Purpose: This syntax is used to extract only a specific column from a table. Query:
  • 5. Select Name FROM STUDENT; OUTPUT: STUDENT Name Jane Sam Changing The Order Of Display Of Column: Syntax: Select {Column1}, {Column2}, {Column3} FROM {Table name}; Purpose: Allows for the rearrange of the structure of a table. Query: Select S. No, Name, Roll. No FROM STUDENT; OUTPUT: STUDENT Changing structure of a table a) To add a column Syntax: ALTER TABLE < Table name > ADD < Column name > [ Data type]; S.No Name Roll. No 1 Jane 2 2 Sam 3
  • 6. Purpose: To add a column in a table, use the following syntax: Query: ALTER TABLE Student profile ADD DOB Date ; OUTPUT: S.no Register no Name Marks DOB 1 4520 Hassan 23 20-05- 2000 2 5022 Talha 45 21-02- 2000 b)To drop a table Syntax: ALTER TABLE < Table name > DROP < Column name > [ Data type]; Purpose: The DROP TABLE statement is used to drop an existing table in a database. Query: ALTER TABLE Student profile DROP DOB Date; OUTPUT:
  • 7. S.no Register no Name Marks 1 4020 Hassan 97 2 5204 Talha 86 c) To modify a column name Syntax: ALTER TABLE < Table name > MODIFY < Column name > < New _ Column name >; Purpose: To modify a column in an existing table, the SQL ALTER TABLE syntax is: Query: ALTER TABLE Student profile MODIFY Register no Reg.no ; OUTPUT: S.no Reg. no Name Marks 1 8572 Hassan 94 2 7857 Talha 86 Retrieving information with SELECT statement I. Retrieving single column Syntax:
  • 8. SELECT < Column name > FROM < Table name >; Purpose: The SELECT statement is used to select data from a database. The data returned is stored in a result table, called the result-set. Query: SELECT Name FROM Student profile; OUTPUT: Student profile Name Hassan Talha II. Retrieving multiple columns Syntax: SELECT < Column name 1 >, < Column name 2 > FROM < Table name >; Purpose: The SELECT statement is used to select data from a database. The data returned is stored in a result table, called the result-set.
  • 9. Query: SELECT Name , Marks FROM Student profile; OUTPUT: Student profile Name Marks Hassan 95 Talha 90 Retrieving all columns Syntax: SELECT * FROM < Table name >; Query: SELECT * FROM Student profile ; OUTPUT: Student profile S.no Reg. no Name Marks 1 1123 Hassan 85 2 1234 Talha 87 Retrieving data from all rows Using arithmetic operators with SELECT Query: SELECT Marks + 5 FROM Student profile;
  • 10. OUTPUT: Student profile Marks + 5 90 92 Query: SELECT Marks – 5 FROM Student profile; OUTPUT: Student profile Marks - 5 80 82 Running a query without a table SELECT 55*2 + 1; Result : 111 Using column alias Syntax: SELECT < Column name > AS < “ New Column name “ > FROM < Table name >; Purpose:
  • 11. SQL aliases are used to give a table, or a column in a table, a temporary name. Aliases are often used to make column names more readable. An alias only exists for the duration of the query. Query: SELECT Reg.no AS “ Register no “ FROM Student profile ; OUTPUT: Student profile Register no 5243 1444 Putting text in query output Query: SELECT S.no , Reg.no , Name , ‘ Class 11B ‘ , Marks FROM Student profile; OUTPUT: Student profile S.no Reg. no Name Class 11B Marks 1 2564 Hassan Class 11B 97 2 1564 Talha Class 11B 90
  • 12. Retrieving Specific Rows - ( Where Class): Syntax: Select * FROM Student WHERE { Condition}; Purpose: This syntax is used to extract only specific rows from a table using logical and relational operators. Query: SELECT * FROM Customers WHERE Country='Mexico'; OUTPUT: Relational operators Syntax: SELECT * FROM < Table name > WHERE < Column name > < Condition >; Query:
  • 13. SELECT * FROM Student profile WHERE Marks = 85; OUTPUT: Student profile S.no Reg. no Name Marks 1 7928 Hassan 85 Query: SELECT * FROM Student profile WHERE Name = ‘ Talha ‘ ; OUTPUT: Student profile Logical operators Query: SELECT * FROM Student profile WHERE Marks > 85 AND Marks < 90; OUTPUT: Student profile S.no Reg.no Name Marks 2 7629 Talha 87 S.no Reg.no Name Marks 2 1512 Talha 87
  • 14. Condition based on range Syntax: SELECT * FROM < Table name > WHERE < Column name > BETWEEN < Condition >; Query: SELECT * FROM Student profile WHERE Marks BETWEEN 80 AND 90 ; OUTPUT: Student profile S.no Reg. no Name Marks 1 7658 Hassan 85 2 1572 Talha 87 Condition based on list Query: SELECT * FROM Student profile WHERE Marks IN ( 85,86,87 ); OUTPUT: Student profile
  • 15. S.no Reg. no Name Marks 1 2316 Hassan 85 2 1210 Talha 87 Condition based on pattern matches Syntax: SELECT * FROM < Table name > WHERE < Column name > LIKE PATTERN < Condition>; Query: SELECT * FROM Student profile WHERE Name LIKE ‘ A% ‘ ; OUTPUT: Student profile S.no Reg. no Name Marks 1 3535 Hassan 85 CREATE TABLE Syntax: CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, ....
  • 16. ); Purpose: The CREATE TABLE statement is used to create a new table in a database. Query: CREATE TABLE Persons ( Person ID int, LastName varchar (255), First Name varchar (255), Address varchar (255), City varchar (255) ); Inserting into a Table Syntax: INSERT INTO < Table name > VALUES ( < Value 1 > , < Value 2 > , ……,< Value N > ); Purpose: The INSERT INTO statement is used to insert new records in a table. Query: INSERT INTO Student profile VALUES ( 1 , 2052 , ‘ Hassan ‘ , 85 );
  • 17. INSERT INTO Student profile VALUES ( 2 , 2053 , ‘ Talha ‘ , 87 ); OUTPUT: Table: Student profile S.no Register no Name Marks 1 2052 Hassan 85 2 2053 Talha 87 Select all the data Syntax: SELECT * FROM < Table name >; Purpose: The data returned is stored in a result table, called the result-set. Query: SELECT * FROM Student profile ; OUTPUT: Table: Student profile S.no Register no Name Marks 1 2052 Hassan 85 2 2053 Talha 87
  • 18. Knowing the current database Syntax: Show database () / Database (); Purpose: SHOW DATABASES lists the databases on the Maria DB server host. SHOW SCHEMAS is a synonym for SHOW DATABASES. Query: Show database (Student profile)/Database (Student profile) OUTPUT: Table: Student profile S.no Register no Name Marks 1 2052 Hassan 85 2 2053 Talha 87 Updating Records Syntax: UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition; Purpose: The UPDATE statement is used to modify the existing records in a table. Query: UPDATE Customers
  • 19. SET Contact Name = 'Alfred Schmidt', City= 'Frankfurt' WHERE Customer ID = 1; OUTPUT: Deleting Records Syntax: DELETE FROM table_name WHERE condition; Purpose: The DELETE statement is used to delete existing records in a table. Query: DELETE FROM Customers WHERE Customer Name='Alfred’s Futterkiste'; OUTPUT:
  • 20. Drop a Table Syntax: DROP TABLE table_name; Purpose: The DROP TABLE statement is used to drop an existing table in a database. Query: DROP TABLE Shippers; SELECT Column Syntax: SELECT * FROM _name; Purpose: The SELECT statement is used to select data from a database. The data returned is stored in a result table, called the result-set. Query: SELECT * FROM Customers; OUTPUT:
  • 21. The SQL SELECT DISTINCT Statement Syntax: SELECT DISTINCT <column1, column2, ...> FROM table_name; Purpose: The SELECT DISTINCT statement is used to return only distinct (different) values. Query: SELECT DISTINCT Country FROM Customers; OUTPUT: The SQL WHERE Clause WHERE
  • 22. Syntax: SELECT column1, column2, ... FROM table_name WHERE condition; Purpose: The WHERE clause is used to filter records. The WHERE clause is used to extract only those records that fulfill a specified condition. Query: SELECT * FROM Customers WHERE Country='Mexico'; OUTPUT: The SQL AND, OR and NOT Operators AND Syntax: SELECT column1, column2, ... FROM table_name
  • 23. WHERE condition1 AND condition2 AND condition 3 ...; Purpose: The AND operator displays a record if all the conditions separated by AND is TRUE. Query: SELECT * FROM Customers WHERE Country='Germany' AND City='Berlin'; OR Syntax: SELECT column1, column2, ... FROM table_name WHERE condition1 OR condition2 OR condition3 ...; Purpose: The OR operator displays a record if any of the conditions separated by OR is TRUE. Query: SELECT * FROM Customers WHERE City='Berlin' OR City='Munched'; NOT Syntax:
  • 24. SELECT column1, column2, ... FROM table_name WHERE NOT condition; Purpose: The NOT operator displays a record if the condition(s) is NOT TRUE. Query: SELECT * FROM Customers WHERE NOT Country='Germany'; OUTPUT: The SQL ORDER BY Keyword Syntax: SELECT column1, column2, ... FROM table_name ORDER BY column1, column2, ... ASC|DESC; Purpose: The ORDER BY keyword is used to sort the result- set in ascending or descending order.
  • 25. The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword. Query: SELECT * FROM Customers ORDER BY Country ASC, Customer Name DESC; OUTPUT: MIN () Syntax: SELECT MIN(column_name) FROM table_name WHERE condition; Purpose: The MIN() function returns the smallest value of the selected column. Query: SELECT MIN(Price) AS Smallest Price FROM Products; OUTPUT:
  • 26. MAX () Syntax: SELECT MAX(column_name) FROM table_name WHERE condition; Purpose: The MAX () function returns the largest value of the selected column. Query: SELECT MAX(Price) AS Largest Price FROM Products; OUTPUT: LIKE
  • 27. Syntax: SELECT column1, column2, ... FROM table_name WHERE columnN LIKE pattern; Purpose: The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards used in conjunction with the LIKE operator:  % - The percent sign represents zero, one, or multiple characters  _ - The underscore represents a single character Query: SELECT * FROM Customers WHERE Customer Name LIKE 'a%'; OUTPUT: BETWEEN
  • 28. Syntax: SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2; Purpose: The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates. The BETWEEN operator is inclusive: begin and end values are included. Query: SELECT * FROM Products WHERE Price BETWEEN 10 AND 20; OUTPUT: SELECT INTO Syntax: Copy all columns into a new table: SELECT * INTO new table [IN external dB]
  • 29. FROM old table WHERE condition; Purpose: The SELECT INTO statement copies data from one table into a new table. Query: SELECT * INTO Customers Germany FROM Customers WHERE Country = 'Germany'; INSERT INTO SELECT Syntax: Copy all columns from one table to another table: INSERT INTO table2 SELECT * FROM table1 WHERE condition; Purpose: The INSERT INTO SELECT statement copies data from one table and inserts it into another table.  INSERT INTO SELECT requires that data types in source and target tables match  The existing records in the target table are unaffected
  • 30. Query: INSERT INTO Customers (Customer Name, Contact Name, Address, City, PostalCode,Country) SELECT Supplier Name, Contact Name, Address, City, Postal Code, Country FROM Suppliers; OUTPUT: GROUP BY Syntax SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) ORDER BY column_name(s); Query
  • 31. SELECT COUNT(CustomerID), Country FROM Customers GROUP BY Country ORDER BY COUNT(CustomerID) DESC; DROP TABLE Syntax: DROP TABLE table_name; Purpose: The DROP TABLE statement is used to drop an existing table in a database. Query: DROP TABLE Shippers; OUTPUT: SQL Arithmetic Operators
  • 32. SQL Bitwise Operators SQL Comparison Operators SQL Compound Operators
  • 33. SQL Logical Operators SQL General Data Types
  • 34. SQL Data Type Quick Reference