Create Table Statement: Structured Query Language
Create Table Statement: Structured Query Language
SQL (Structured Query Language) is a computer language aimed to store, manipulate, and
retrieve data stored in relational databases.
So, if we are to create the customer table specified above, we would type in:
Once a table is created in the database, there are many occasions where one may wish to change
the structure of the table. Typical cases include the following:
- Add a column
- Drop a column
The SQL syntax for ALTER TABLE is:
Alter Table
This allows persons to make changes to a table in a database, in relation to: Add, drop or change
information.
1. Drop Column:
ALTER Table student
DROP Address;
2. Add Column
3. DELETE ROW
DELETE FROM student
WHERE STUID=115;
The syntax for inserting data into a table one row at a time is as follows:
Insert Into
INSERT INTO student (STUID, FName, LName, Gender, Tel, Test1, Test2)
The GROUP BY keyword is used when we are selecting multiple columns from a table (or
tables) and at least one arithmetic operator appears in the SELECT statement. When that
happens, we need to GROUP BY all the other selected columns, i.e., all columns except the
one(s) operated on by the arithmetic operator.
Group By
This is normally used in the case of calculated fields.
SELECT FName,sum(Average)
FROM student
GROUP BY FName;
So far, we have seen how to get data out of a table using SELECT and WHERE commands.
Often, however, we need to list the output in a particular order. This could be in ascending order,
in descending order, or could be based on either numerical value or text value. In such cases, we
can use the ORDER BY keyword to achieve our goal.
SELECT "column_name"
FROM "table_name"
ORDER BY "column_name" [ASC, DESC]
Order By
SELECT LName, FName, Gender
FROM student
OR
OR
ASC means that the results will be shown in ascending order, and DESC means that the results
will be shown in descending order. If neither is specified, the default is ASC.