CREATE TABLE Statement

Access SQL
  • Syntax
  • Examples
  • Advanced

Syntax - Basic Create Table:

CREATE TABLE TableName(
  TableName DataType Constraint
);



What does it do?
The Access SQL CREATE TABLE statment creates a new table with specified columns and constraints in the database. When adding more than one column and a comma after the previous columns' constraint. Note: don't add a comma after the last column that will break the SQL Statement.




Common Data type list:

AutoIncrement This automatically increments the field value. In the designer it is called the AutoNumber.
Integer This translates to long integer in the designer. It represents a number ranging from -2,147,483,648 to 2,147,483,647.
Varchar This tranlates to Text in the desginer. It represents string of characters up to 255.
YesNo This translates to Yes/No in the desginer. It represents a boolean value(true or false), it may show up as a 'Yes' or 'No', 'true' or 'false', '0' or '-1' depending on if you working with the table in VBA or your linking to a SQL Server table etc.
DateTime This translates to Date/Time in the designer. It represents a full date and time value.
Double This translates to Number with a field size of Double in the designer. It represents a decimal number.
*There are more data types than this, also some have synonyms.

Example:

CREATE TABLE Customers(
Id AUTOINCREMENT PRIMARY KEY,
FirstName VARCHAR(35) NOT NULL,
LastName VARCHAR(35) NOT NULL,
IsActive YESNO,
RegistrationDate DATETIME,
Email VARCHAR(100)
);


Results: The table in the designer will look like this.

Id AutoNumber
FirstName Text
LastName Text
IsActive Yes/No
RegistrationDate Date/Time
Email Text

Legend

Blue - Is used to identify reserved keywords/characters that are used by the SQL engine, i.e. SELECT, FROM, or WHERE.


Purple - Is used to identify portions of the SQL statement that are defined by the user, i.e. Column Names, Table Names, Inputed Values.