Creating Tables on the Fly

Results 1 to 4 of 4

Thread: Creating Tables on the Fly

  1. #1
    Loren Erickson Guest

    Default Creating Tables on the Fly

    Is is possible to make a script that creats a table on the fly? I want to be able to add new customers in and admin area, and they can have there oun table of information named by there letter code. This table would have all the basics and be pretty much generic to the rest.<BR>if anyone can help that would be great.<BR>Thanks<BR>Loren

  2. #2
    chris willey Guest

    Default RE: Creating Tables on the Fly

    You can use SQL for this:<BR><BR>create table TABLENAME (FIELD1 DATATYPE NULL&#124NOT NULL, FIELD2 DATATYPE NULL&#124NOT NULL)<BR><BR>Here&#039s a more complete example:<BR><BR>dim connect, newtable<BR>set connect = server.createobject("adodb.connection")<BR>connect .open "mydb"<BR>set newtable = connect.execute("create table mytable (id integer not null, myfield char(40) null)")<BR><BR>The datatypes you can use will vary depending on your DBMS.<BR><BR>Here&#039s a useful SQL reference for ya:<BR><BR>

  3. #3 Guest

    Default Possible, but is it a good idea? I think not!

    It is quite simple:<BR><BR>&#060;%<BR>custId=Request("CustID") &#039 Get customers id<BR><BR>Set Conn=Server.CreateObject("ADODB.Connection")<BR>Co ConnectionString<BR>tSQL="create table Admin" & custId & " (field1 text)"<BR>Conn.Execute tSQL<BR>%&#062;<BR><BR>The tSQL variable is assigned a the SQL command string, which is the create table statement. My statement creates a table with one text field, and the table is named by the customer id. <BR><BR>But, I do not think that this approach is a sound one, as you are creating a new table for each customer. This is not good database design. The way it should be done is to have one table which contains an index field for each customer, and you store the main details of the customer in that table (eg CustId). You might then have related tables for orders or contracts or whatever else you want to store about him. The rows of related tables would also have the custid as part of their index.<BR><BR>My code example shows you how to do what you asked for but I recommend against it.

  4. #4
    Join Date
    Dec 1969

    Default Check out, FAQ # 8

    Check out this popular FAQ at<BR><BR>How do you create a database table through a SQL statement (via an ASP page, perhaps)?<BR><BR><BR>A number of database-related FAQs can be viewed at:<BR><BR><BR>Happy Programming!<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts