Tuesday, 11 October 2011

SQL CREATE TABLE Statement

The CREATE TABLE Statement

The CREATE TABLE statement is used to create a table in a database.

SQL CREATE TABLE Syntax

CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
....
)

The data type specifies what type of data the column can hold. For a complete reference of all the data types available in MS Access, MySQL, and SQL Server, go to our complete Data Types reference.


CREATE TABLE Example

Now we want to create a table called "Persons" that contains five columns: P_Id, LastName, FirstName, Address, and City.

We use the following CREATE TABLE statement:

CREATE TABLE Persons
(
P_Id int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)

The P_Id column is of type int and will hold a number. The LastName, FirstName, Address, and City columns are of type varchar with a maximum length of 255 characters.

The empty "Persons" table will now look like this:

P_Id LastName FirstName Address City
         

The empty table can be filled with data with the INSERT INTO statement.


7 comments:

  1. I have read so many articles regarding the blogger lovers except this paragraph
    is genuinely a fastidious article, keep it
    up.

    Here is my weblog :: minecraft demo

    ReplyDelete
  2. naturally like your web site however you have to test the spelling on quite a few of
    your posts. A number of them are rife with spelling problems and
    I to find it very bothersome to tell the reality however I'll
    certainly come again again.

    My webpage ... quest bars

    ReplyDelete
  3. You are so interesting! I do not think I've truly read
    anything like that before. So wonderful to discover another person with a few original thoughts on this topic.
    Really.. many thanks for starting this up. This
    site is something that is needed on the web, someone with some originality!


    Here is my webpage Diet Plans for Women to Lose Weight

    ReplyDelete
  4. This piece of writing is really a good one it helps new net
    viewers, who are wishing for blogging.

    My site; Lose Weight for Women

    ReplyDelete
  5. Howdy! This blog post could not be written much better! Looking through this article reminds me of my
    previous roommate! He continually kept preaching about this.

    I most certainly will forward this post to him. Fairly certain he's going to have a very good read.
    Thanks for sharing!

    Here is my page: Diet Plans to Lose Weight

    ReplyDelete
  6. It's awesome in support of me to have a web site, which is good in support of my know-how.
    thanks admin

    Here is my blog post - Diet Plans to Lose Weight

    ReplyDelete
  7. It's genuinely very complex in this busy life to listen news on TV, therefore I just use world wide
    web for that purpose, and obtain the most up-to-date news.


    Here is my web-site: coconut oil for hair

    ReplyDelete