Read this chapter. Take notes and be able to provide details about SQL, data definition language (DDL), data manipulation language (DML), and Structured English Query Language (SEQUEL).
SQL is a universal and standard language that interfaces with relational databases. SQL is used to communicate, analyze, and provide results from the data fields stored in a relational database. This next section will cover user-defined SQL objects, also known as functions. Your ability to understand and specify functions reduces the chance of errors in your SQL programming code. Also, remember when we discussed SQL injection attacks while looking at database security? Poorly constructed SQL code is what makes these kinds of attacks possible.
Create Database
The major SQL DDL statements are CREATE DATABASE and CREATE/DROP/ALTER TABLE. The SQL statement CREATE is used to create the database and table structures.
Example: CREATE DATABASE SW
A new database named SW is created by the SQL statement CREATE DATABASE SW. Once the database is created, the next step is to create the database tables.
The general format for the CREATE TABLE command is:
CREATE TABLE <tablename>
(
ColumnName, Datatype, Optional Column Constraint,
ColumnName, Datatype, Optional Column Constraint,
Optional table Constraints
);
Tablename is the name of the database table such as Employee. Each field in the CREATE TABLE has three parts (see above):
- ColumnName
- Data type
- Optional Column Constraint
ColumnName
The ColumnName must be unique within the table. Some examples of ColumnNames are FirstName and LastName.