add a new table to the database or add a new column to an existing table.

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2007
Posts: 98
Reputation: GLT is an unknown quantity at this point 
Solved Threads: 0
GLT GLT is offline Offline
Junior Poster in Training

add a new table to the database or add a new column to an existing table.

 
0
  #1
Apr 7th, 2008
Hey guys!

I was wondering if anyone could help me. I am a student on my work placement year and I am developing a web based database. I have been asked to design it so users can if need be add a new table to the database or add a new column to an existing table. I have never done this before, how would I go about doing this?? I was thinking that I would have to use some kind of stored procedure and a form the users could fill in? but I have no idea where to start.

I am using Dreamweaver MX and Access, I will be using SQL Server but I am using Access at the minute to create a practice dummy site.

Thanks!
Any ideas would be greatly appreciated!

GLT

(I have asked this same question in the ASP forum but getting no responses)
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,182
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 481
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: add a new table to the database or add a new column to an existing table.

 
0
  #2
Apr 7th, 2008
Create table
  1. CREATE TABLE table_name
  2. (
  3. column_name1 data_type,
  4. column_name2 data_type,
  5. )
The problem that you facing here is
  1. Table is always same so you just run your prepared statement
  2. Tables can be different, you must provide a way/interface through which user can declare table name, column types, you just add the magic words CREATE TABLE and then execute it
Add column
  1. ALTER TABLE table_name
  2. ADD column_name datatype
Remove column
  1. ALTER TABLE table_name
  2. DROP COLUMN column_name
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 98
Reputation: GLT is an unknown quantity at this point 
Solved Threads: 0
GLT GLT is offline Offline
Junior Poster in Training

Re: add a new table to the database or add a new column to an existing table.

 
0
  #3
Apr 7th, 2008
Hi thanks for replying!

I do know the SQL for creating and altering tables but I was wondering if anyone had any idea how I would get information from a form or something in dreamweaver to then create the table. The users dont know much about programming or database's so I was hoping to make a simple form or something for them to fill out. Is this possible??

ideas would be greatly appreciated!
Thanks!
GLT
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,182
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 481
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: add a new table to the database or add a new column to an existing table.

 
0
  #4
Apr 7th, 2008
Ofcourse it is possible, you just have to tell us which technology you plannig to use. PHP/JSP/ASP/ Ruby on Rails? Also so proper scenario to explain situation would help.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 98
Reputation: GLT is an unknown quantity at this point 
Solved Threads: 0
GLT GLT is offline Offline
Junior Poster in Training

Re: add a new table to the database or add a new column to an existing table.

 
0
  #5
Apr 8th, 2008
Thank you,

I'm using ASP with SQL Server 2005. The web based database that I am developing will hold details of the companies products and customers, their orders and enquiries. I have developed a database structure for this but I am only here for a few more months (I am a student on placement), the company want me to include a way so they can add new columns to existing tables if they need to store extra info and so they can add new tables if need be.

GLT
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,182
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 481
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: add a new table to the database or add a new column to an existing table.

 
0
  #6
Apr 8th, 2008
For ASP development I would recommend to use Visual Studio, that you can get for free from Microsoft website .

Back to your project...
You been given task that is nearly extensive as final year project. I would recommend you have look on few SQL Browser interfaces such as phpMyadmin, MySQL Query Browser, SQL Server Management Studio Express or any other so you get idea what you need to provide for user.
Do not go extensive on it, given them just basic options so they do not mess up anything. You should just offer option to select in which database new table should be created, text field for table name, then text fields for column names (make sure that table and variables names appropriate not special characters such as comas, dots, slash etc), drop down options for variable types (just work out what are most common variable types they use, you do not need all of them) and possible initial values (for this I would recommend you have good look at phpMyadmin).
Adding new collumn approach is somewhat similar to creating new table, but this time you have to select database and table.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 98
Reputation: GLT is an unknown quantity at this point 
Solved Threads: 0
GLT GLT is offline Offline
Junior Poster in Training

Re: add a new table to the database or add a new column to an existing table.

 
0
  #7
Apr 9th, 2008
Hi, Thanks for you help!

This is what ive got so far... it may be completely wrong but am I on the right lines??

stored procedure:-

  1. CREATE PROCEDURE sp_createtable
  2. AS
  3. CREATE TABLE @txttablename
  4. (
  5. @txtcolumn1 adText adParamInput txtcolumn1,
  6. @txtselect1 adText adParamInput txtselect1,
  7. @txtcolumn2 adText adParamInput txtcolumn2,
  8. @txtselect2 adText adParamInput txtselect2,
  9. @txtcolumn3 adText adParamInput txtcolumn3,
  10. @txtselect3 adText adParamInput txtselect3,
  11. )

asp:-

  1. ' Declare variables
  2. <%
  3. Dim cmdcreatetable
  4. Dim txttablename
  5. Dim txtcolumn1
  6. Dim txtselect1
  7. Dim txtcolumn2
  8. Dim txtselect2
  9. Dim txtcolumn3
  10. Dim txtselect3
  11.  
  12. ' Get VALUES FROM form
  13. txttablename = Request.Form("txttablename")
  14. txtcolumn1 = Request.Form("txtcolumn1")
  15. txtselect1 = Request.Form("txtselect1")
  16. txtcolumn2 = Request.Form("txtcolumn2")
  17. txtselect2 = Request.Form("txtselect2")
  18. txtcolumn3 = Request.Form("txtcolumn3")
  19. txtselect3 = Request.Form("txtselect3")
  20.  
  21. ' Set Command
  22. Set cmdcreatetable = Server.CreatObject("ADODB.Command")
  23. cmdcreatetable.ActiveConnection = strConn
  24. cmdcreatetable.CommandText = sp_createtable
  25. cmdcreatetable.CommandType = adCmdStoredProc
  26.  
  27. ' ADD Parameters
  28. cmdcreatetable.Parameters.Append.CreateParameter("@txttablename", adText, adParamInput, txttablename)
  29. cmdcreatetable.Parameters.Append.CreateParameter("@txtcolumn1", adText, adParamInput, txtcolumn1)
  30. cmdcreatetable.Parameters.Append.CreateParameter("@txtselect1", adText, adParamInput, txtselect1)
  31. cmdcreatetable.Parameters.Append.CreateParameter("@txtcolumn2", adText, adParamInput, txtcolumn2)
  32. cmdcreatetable.Parameters.Append.CreateParameter("@txtselect2", adText, adParamInput, txtselect2)
  33. cmdcreatetable.Parameters.Append.CreateParameter("@txtcolumn3", adText, adParamInput, txtcolumn3)
  34. cmdcreatetable.Parameters.Append.CreateParameter("@txtselect3", adText, adParamInput, txtselect3)
  35.  
  36. ' Execute the command
  37. cmdcreatetable.Execute
  38. %>
  39.  

SQL Server doesnt like the @ symbol but I dont know how else to do this.
the asp code - the select text boxes are for the user to input datatype.

Thanks for all you help! all ideas greatly appreciated!

GLT
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 98
Reputation: GLT is an unknown quantity at this point 
Solved Threads: 0
GLT GLT is offline Offline
Junior Poster in Training

Re: add a new table to the database or add a new column to an existing table.

 
0
  #8
Apr 9th, 2008
Ive been having aply with my code and trying to find information on this. It looks like I have to use dynamic SQL which I have never used before. Here is the SQL code I have now:-

  1. CREATE PROCEDURE sp_createtable
  2. (
  3. @txttablename AS varchar(50),
  4. @column1 AS varchar(50),
  5. @select1 AS varchar (50),
  6. @column2 AS varchar(50),
  7. @select2 AS varchar(50),
  8. @column3 AS varchar(50),
  9. @select3 AS varchar(50)
  10. )
  11. AS
  12. DECLARE @SQL varchar(2000)
  13. SELECT @SQL = 'create Table' + @txttablename+')'
  14. SELECT @SQL = @SQL + 'ID identity NOT NULL PRIMARY KEY, @txtcolumn1 @txtselect1, @txtcolumn2 @txtselect2, @txtcolumn3 @txtselect3)'
  15. Exec(@SQL)

is this right? my SQL Server is down at the minute so I cant test it. I am trying to insert the tablename, column names and datatype from as asp form.

ideas would be great!
Thanks GLT
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,182
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 481
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: add a new table to the database or add a new column to an existing table.

 
0
  #9
Apr 10th, 2008
Sorry I can't advice in regards of last 2 posts as I'm more Java and MySQL oriented. The SQL statement that you wrote is different from what I normaly use. Currently I'm also looking into C#, maybe you will find useful chap.21&22 from C# for Programmers, Second Edition that is from Deitel Developer Series

I can discuse designer issues in regards of your project, however for practical problem solving you better post your questions in ASP.NET section of this forum
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC