SQL Statement 2
SQL statements 2
Update, alter, drop statementSQL ALTER TABLE Statement
The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.
The ALTER TABLE statement is also used to add and drop various constraints on
an existing table.
We will modify and add a column called City to our table
Now we will check
We will update the city for everyone
We will confirm and now everyone just moved to Miami!
We will move one user to Tampa: Alex Rodriguez
We will verify
Now we will drop this table
Now we will create another table with a primary key and identity 1,1 so they will be added automatically
the results is positive as we can see..
Now the Food Order table:
Now we will inset some data into the table
Now let 's run some information because one of the players was hungry
Pedro Martinez got some fries!
Now create several orders in the same way..altering the numbers and executing them
So, who buy what and what is the total amount?
Let's double check ourt tables values first
SQL PRIMARY KEY Constraint
The PRIMARY KEY constraint uniquely identifies each record in a database table.
Primary keys must contain UNIQUE values, and cannot contain NULL values.
A table can have only one primary key, which may consist of single or multiple field
Check the keys in our table
SQL INNER JOIN Keyword
The INNER JOIN keyword selects records that have matching values in
both tables.
Now let's join our tables together !
We will execute and this is the positive results..
WE can use an "alias."..
and simplify more than that..
let's make this table shorter!
The SQL GROUP BY Statement
The GROUP BY statement is often used with aggregate functions (COUNT, MAX,
MIN, SUM, AVG) to group the result-set by one or more columns.
We will try to find out the total amount of money spend
We can find out how much each one spends
And we can do that by City
So, we can see there is a lot of function in SQL...
I hope that you enjoy this lab..
In case that you have any questions, Please don't hesitate to ask
SQL Statement 2
Reviewed by ohhhvictor
on
6:55 PM
Rating:
No comments: