Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/sites/ on line 10 Using SQL to Create a Database Table -

Using SQL to Create a Database Table

An easy way to create a new database table is through the use of an SQL (Structured Query Language) query. To execute SQL queries you will need to use the SQL query editor of your chosen database. For SQL server, use the Management studio to create a new query by right clicking on the database and selecting “New Query”.

To create the table you must firstly specify the table name, and then the column names and data types within the brackets as illustrated below. You can specify as many columns as required, with the option of specifying if nulls are allowed. To allow nulls omit the NOT NULL text in the column definition.

The data types you can specify depend on the database being used.

Examples of SQL Server data types:

  • Int – For integers.
  • Real – For floating point values (values with a decimal place e.g. 1.34).
  • Varchar(length) - for text values. Length being the maximum number of characters.
  • Bit – for Boolean values.

SQL Script:

[Column 1 Name] [Data Type] NOT NULL,
[Column 2 Name] [Data Type] NOT NULL,
[Column 3 Name] [Data Type] NOT NULL,
[Column 4 Name] [Data Type] NOT NULL)

Return to all articles