SQL CREATE DATABASE, CREATE TABLE, and ALTER TABLE
Tweet |
The CREATE DATABASE statement is used to create a new SQL database and has the following syntax:
CREATE DATABASE DatabaseName
The CREATE DATABASE implementation and syntax varies substantially between different RDBMS implementations.
The CREATE TABLE statement is used to create a new database table. Here is how a simple CREATE TABLE statement looks like:
The DataType specified after each column name is a placeholder fro the real data type of the column.
The following CREATE TABLE statement creates the Users table we used in one of the first chapters:
The CREATE TABLE statement above creates a table with 3 columns - FirstName of type CHAR with length of 100 characters, LastName of type CHAR with length of 100 characters and DateOfBirth of type DATE.
The ALTER TABLE statement is used to change a table definition by adding, modifying or dropping columns. Below you can see the syntax of an ALTER TABLE statement, which adds a new column to the table:
If we want to delete the newly added ColumnName column we can do it with the following ALTER TABLE statement:
If your site has a huge amount of traffic, which results to a lot of queries to the database, try migrating into one of those virtual private servers that other web hosting providers offer.