Sql
Table
This table in the database is named as CustomerOrder
Customeri Name phone Order city addres Productid
d date s
1001 Aiza 030074523 15-03- Multan Street Pwwe234
khan 12 2023 no 12 3
Liaqat
road
1002 Marya 034156342 12-06- Faisalaba DHA Lefie786
m wakil 34 2023 d 3
1003 Ali 030343932 15-06- Bahawalp Near Lefie786
Murtaz 88 2023 ur noor 3
a mahal
1004 Rafia 038112893 19-08- Multan DHA Abisj203
Sami 90 2023 4
1005 Hooria 034383894 15-03- Lahore Aziz Skdsl233
Fatima 29 2024 Bhatti 4
town
1006 Arzoo 034343879 25-09- Multan DHA Pwwe234
Kazmi 23 2024 3
1007 Abdulla 030083849 23-09- Sahiwal Near Lekld343
h 29 2024 army 4
Hamda public
n school
1008 Arooj 030917239 04-01- Faisalaba D Lefie786
Fatima 29 2025 d ground 3
1009 Rehab 030723804 09-03- Lahore DHA Abisj203
Agarwa 03 2025 4
l
1010 Rema 031293939 18-06- Faisalaba 202RB Pwwe234
khan 04 2025 d Gatti 3
We link this table with a product table
We give this table name Products
ProductID Price
Pwwe2343 2500
Lefie7863 3000
Abisj2034 1800
Skdsl2334 2600
Lekld3434 2800
This table is linked using the foreign key so we can easily
Create database
This show us on the action output as
As the database created we use this database as
This will appear as
Now we create the table
We write the following code in our my sql
CREATE TABLE CustomerOrders (
CustomerID INT PRIMARY KEY,
Name VARCHAR(100),
Phone VARCHAR(15),
OrderDate DATE,
City VARCHAR(50),
Address VARCHAR(255),
ProductID VARCHAR(20),
FOREIGN KEY (ProductID) REFERENCES Products(ProductID)
);
This will run on the output window
We create this table and also involve the foreign key table
The foreign key table is
This show as
We run this table before the overall table
As table created we will insert the value in the table
First insert the value in the foreign key table
This will show
Now we insert the value in the table
This will created
Now we will do the operation on our table as the table is ready and we have
inserted the value
Using select we can see the created table
Type of sql commands:
DQL:
It stand for data query language
It include the SELECT command only as I use it in all other type to show the
changes therefore I want to discuss it first
SELECT:
Used to show data to the user or retrieve data from a table or from a
database
Select a value of your choice
I write this command
And after running this it show me like this
Select the whole table
I show the code the output in the same ss
Select and use with order by to arrange data or sort the result
Here all the elements are arrange with respect to date in descending order
WHERE is used with SELECT to filter the row
We run this command on our sql server as a result only the selected values
only come out
GROUPED BY is used with select to place the values in the groups
Its output is shown as
Here we grouped the cities that to know how many orders have been down
from a city
HAVING is also used with SELECT to filter the group result
In this we have give a condition to our table
So this is all related the SELECT query which I used in all my sql commandsto
show the output
DDL:
It stand for data definition language
It include the following commands
CREATE:
Use to create a table and a database
We create database
We create a table
Create is used for view also
View is create
Similarly a view of precise data can be generated
Which show as
We can see our created view by using select command
Although it is not involved in ddl but let me show the view which is created
by using create command
We write command snd it appear as
This is view which we create using create command
Alter
Alter command used to change in the table or modify the table
First of all we let see our created table by using select command so we can
easily see the changes in our database
So this is our table let see the changes in our database by using alter
commands
The output and the command are in the same ss
As I alter the table instide of price it show the email which we can insert
easily
DROP
It is used to deleted database ,a table ,a row or an column permanently
Drop a colum
So after using this price colum is drop we drop address column in this table
Drop a row
The drop row can be seen by the select command
you can see that the customer id 1005 has been removed
before it completely showing in our database
After dropping the table this show us in our mysql
TRUNUCATE
It remove all the removes but keep the structure
Before it was like
After truncate
So this only kept the structure
DML
It is stand for Data Manipulation Language
It include the following commands
Insert
Update
Delete
INSERT
Add new record or some value in our table