Server Time:
Sunday May 11 2008 08:06 PM  
Your Time:
  
HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

Creating, Altering and Deleting database tables with ColdFusion.
by: Pablo Varando
Email this tutorial to a friend Display Printer Friendly Format
[Download in PDF Format] [Download in FlashPaper Format]

Creating, Deleting and modifying database tables on the fly with ColdFusion.

This tutorial will demonstrate how to create tables in your database using your ColdFusion applications! Let's begin:

the Create table statement creates a new database table in the specify datasource.
(Please note : syntax varies from database to database. [ This code has been tested in Access and SQL Server 2000 ])

<!--- This will create the tables on the database --->
<cfquery name=
"qCreateTable"  datasource="MyDSN">
    CREATE TABLE Members (
                            member_id counter Primary Key,
                            member_fname varchar(255),
                            member_lname varchar(255),
                            member_age integer,
                            member_visits numeric,
                            CONSTRAINT ID PRIMARY KEY(ID)
                            )
</cfquery>

The next thing you need to learn is how to delete a table on the fly, you do this with the "DROP TABLE" command. The Drop statement deletes an existing table (including all data) in the specify datasource.

<!--- This will completely delete a table and all items in it --->
<cfquery name=
"qDeleteTable" datasource="MyDSN">
        DROP TABLE Members 
</cfquery>

The next step is to modify fields in a table with the ALTER TABLE statement:

<!--- This will alter a column in the table --->
<cfquery name=
"qAlterTable" datasource="MyDSN">
        ALTER TABLE Members
        ALTER COLUMN member_visits Long
</cfquery>

<!--- This will alter a table by deleting the column --->
<cfquery name=
"qDeleteFieldFromTable" datasource="MyDSN">
        ALTER TABLE Members
        DROP COLUMN member_visits
</cfquery>

Question? Comments? Email me....


Date added: Mon. October 14, 2002
Posted by: Pablo Varando | Views: 25159 | Tested Platforms: CF5 | Difficulty: Intermediate
Categories Listed: Databases SQL

HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

This author's other tutorials:
Delete files and folders in a specified path!
This tutorial will demonstrate how you can delete all files and sub-folders in a specified folder using ColdFusion and Windows! - Date added: Wed. September 7, 2005
Dynamic Last Date Modified?
This tutorial will demonstrate how to display the date a web page was last modified to your visitors dynamically. - Date added: Mon. April 12, 2004
Correct Content (document) serving!
This tutorial will demonstrate how to correctly serve documents via ColdFusion and allow you to correctly name the download as you see fit! - Date added: Tue. February 10, 2004
Creating your very own RSS XML Feeds with ColdFusion MX!
Have you ever wanted to create your very own RSS XML News Feeds? This tutorial will show you how to create an RSS feed that will allow you to syndicate your web site and allow the world to easily use your data! - Date added: Thu. January 15, 2004
Processing XML/RSS feeds with ColdFusion MX
This tutorial will show you how to parse XML files (RSS Feeds) with ColdFusion MX and it uses an EasyCFM.COM Feed for example [Feed: 5 Most Viewed Tutorials]. It shows you how to call it via CFHTTP all the way to parse and display your records! - Date added: Sat. December 27, 2003

Additional Tutorials:
· Changing the form submission page on the fly!

· What is the ID for the record I just inserted?

· Creating a file content crawler with ColdFusion....

· Delete Records From Your Database With ColdFusion!

· Do you want to remember your members?

· Get A Folder Size Using ColdFusion and FSO...

· Preventing People From Leeching Your Images!

· Combining two queries into one..

· CaSe SensitiVe password logins!

· Creating an ODBC Connection within ColdFusion MX Server...

· Print your web pages on the fly!

· Using <CFPOP> and creating an email client for POP3 Email Reading!

· Using CFRegistry to Add Your IP To CF Debug IP List!

· Reading your IIS Log Files with ColdFusion!

· Automatically Adding Smiles To Your Messages!

· Using Arrays in ColdFusion To Properly Display Data....

· Implementing FORM Error Checking On Your Pages!

· Inserting FORM data into multiple database tables!

· Sending multiple attachments with CFMAIL!

· ColdFusion and .INI Files!

· Clearing your session variables!

· Using PayPal's IPN with ColdFusion!

· Alternating Row Colors!

· Previous / Next n Records

· Using Query String Values....

· A quick intro into the world of Custom Tags!

· A brief demonstration of Fusebox 2.0

· Creating a Newsletter System....

· Count Active Users On Your Site.

· User Defined Functions....

· Creating a user athentication (Login) area.

· DSNLess Coldfusion?

· A Simple Contact Us Page….

· Having Your Database Do The Work… not ColdFusion!

· Retrieving Records From a Database..

· Inserting data into a database
Please rate this tutorial:
5 Stars 4 Stars 3 Stars 2 Stars 1 Stars
Comments on this tutorial
Read previous comments on this particular tutorial
table names
Is there a way to list the tables in a mysql database for the user to view and work from? version 5

Posted by: chris
Posted on: 11/06/2004 09:21 PM
interesting site
i would like more information about creation of table connecting rows and columns and more information about deleting and adding new records
Posted by: pravesh
Posted on: 12/13/2007 04:01 AM
Post a new comment on this tutorial
post a new comment on this particular tutorial
Your Name:
Your Email:
Comment Title:
Comments:
Key Phrase:
 
Skyscrapper Banner Advertisement
ColdFusion Hosting by HostMySite

You are 1 of 639 active sessions! | Privacy | Company
Copyright © 2002 EasyCFM.Com, LLC. (Easy ColdFusion Tutorials) All Rights Reserved
All other trademarks and copyrights are the property of their respective holders.
ColdFusion Hosting ColdFusion Hosting
ADD TO:
Blink
Del.icio.us
Digg
Furl
Google
Simpy
Spurl
Y! MyWeb