Welcome to my ASP Code Website

Create a Table with SQL Syntax



Need to create a table to put data in? It's very easy to put together SQL Syntax to build the table to store your newsletter members, poll votes, or more.

To start with, get a connection to your databse using ODBC, Access, PowerBuilder, or whatever other tool you use. Open up a SQL window so you can submit a SQL command to your database.

Now for the syntax. The general syntax to create a table is

CREATE TABLE tablename (field1 type1, field2 type2, field3 type3 ...);

So let's say you want to create a table called MEMBERS which holds your newsletter members in it. The fields you are tracking are memb_email, memb_date to know when each person joined you. You would say:

CREATE TABLE members (memb_email varchar(50), memb_date datetime);

The most commonly used field types are:

int
char(#)
varchar(#)
datetime

The char field is best used when you are always going to have a set number of letters. So this is good to use for char(1) if you are doing a nl_type of H for HTML and T for text. The varchar field is best used when the character lengths will always be different, such as when you are taking in email addresses of varying lengths.

SQL Command Listing