Author |
Topic  |
|
Da_Stimulator
DEV Team Forum Moderator
    
USA
3373 Posts |
Posted - 01 November 2001 : 14:44:52
|
I was wondering how I would do this (via the web), since I dont have access or a third party program to use access on my computer... I dont want to delete the table then create a new one with the changed name, because there are alot of columns and information already in the table, and it would take hours.
I had just realized the table name I'm using might conflict with others if used with SQL server, and I need to re-name it via web so I can test it with my current setup.
Any Idea's?
--------------- -Da_Stimulator |
|
Da_Stimulator
DEV Team Forum Moderator
    
USA
3373 Posts |
Posted - 01 November 2001 : 15:03:39
|
ok I've done extensive research around the net, and have found nothing on editing a table's name, so i assume it cannot be done.
what about getting all of the columnames and properties (eg count, memo, in etc...) from a table, store them in variables, delete the table, create a new one and populate it with those values...
I would have to deal with re-populating the table.
The only problem is I dont know how to get the column information from the table.
--------------- -Da_Stimulator |
 |
|
redbrad0
Advanced Member
    
USA
3725 Posts |
Posted - 01 November 2001 : 15:13:16
|
Check out http://www.2enetworx.com/dev/projects/tableeditor.asp its an online database utility. I use this on my sql servers. you can edit the tables, but i dont think you can edit the table name. I think you will have to create the new table, the transfer all the data into the new table, then delete the old table. Im not sure how to read what each column is, but If you look in the code in the /te_tableedit.asp file it does display the column names, field type, size, and attributes
Brad |
 |
|
Da_Stimulator
DEV Team Forum Moderator
    
USA
3373 Posts |
Posted - 01 November 2001 : 15:24:23
|
thats what I am using, cant edit table names though.
--------------- -Da_Stimulator |
 |
|
Da_Stimulator
DEV Team Forum Moderator
    
USA
3373 Posts |
Posted - 01 November 2001 : 15:27:33
|
Ok, I have the basics down... (I'm going to release this as a separate free script on my site when I'm done...) - now I just need to figure out how to get the field sizes (eg varchar 100) etc...
--------------- -Da_Stimulator |
 |
|
GauravBhabu
Advanced Member
    
4288 Posts |
Posted - 01 November 2001 : 15:29:27
|
Table editor is a good example of how to get the column names etc. Look at te_listtables in Table Editor files.
GauravBhabu There is only one miracle...That is LIFE! | It is difficult to IMPROVE on Perfection, There is no harm in Keep Trying. |
 |
|
GauravBhabu
Advanced Member
    
4288 Posts |
Posted - 01 November 2001 : 15:34:42
|
For field Types look te_tableedit.asp in Table Editor files
basically it goes like this
quote: From te_tableedit.asp
rs.Open "[" & sTableName & "]",,,adCmdTable if rs.fields.count = 0 then response.write "No fields defined for table." CloseRS %><!--#include file="te_footer.asp"--><% response.end end if if err <> 0 then response.write err.number & ":" & err.description & "<br><br>" end if for each fld in rs.fields sFieldType = "" sAttributes = "" select case fld.Type case adSmallInt : sFieldType = "integer" case adInteger : sFieldType = "long"
GauravBhabu There is only one miracle...That is LIFE! | It is difficult to IMPROVE on Perfection, There is no harm in Keep Trying. |
 |
|
Da_Stimulator
DEV Team Forum Moderator
    
USA
3373 Posts |
Posted - 01 November 2001 : 15:36:06
|
I already did, I already have a sub set up to make the new queryline to create the table BUT I still need to find out how to get the sizes of the fields eg field1 is varchar (100)
CONST adOpenStatic = 3, adLockReadOnly = 1, adCmdText = &H0001
Sub RenameTable(strTable, strNewTable) ' this sub gathers the names and data ' types of fields for a given table. Dim objRs, strSQL, i, strOutput Set objRs = Server.CreateObject("ADODB.Recordset") strSQL = "SELECT * FROM " & strTable & ";" objRs.Open strSQL, t_conn, adOpenStatic, adLockReadOnly, adCmdText ' access the fields collection for this table strCNtable = "CREATE TABLE " & strNewTable & " " For i = 0 to objRs.fields.count -1 strCNtable = strCNtable & objRs.fields(i).name & " " & DataTypeName(objRs.fields(i).type) ' & SIZE VALUE HERE Next objRs.Close Set objRs = Nothing End Sub
--------------- -Da_Stimulator |
 |
|
GauravBhabu
Advanced Member
    
4288 Posts |
Posted - 01 November 2001 : 15:49:09
|
objRs.fields(i).definedsize
and for attributes
objRs.fields(i).attributes
GauravBhabu There is only one miracle...That is LIFE! | It is difficult to IMPROVE on Perfection, There is no harm in Keep Trying.
Edited by - gauravBhabu on 01 November 2001 15:51:08 |
 |
|
Da_Stimulator
DEV Team Forum Moderator
    
USA
3373 Posts |
Posted - 01 November 2001 : 15:58:02
|
ok thx :) Can someone proofread this before I go and screw up my database?
<% CONST adOpenStatic = 3, adLockReadOnly = 1, adCmdText = &H0001
Sub RenameTable(strTable, strNewTable) ' this sub gathers the names and data ' types of fields for a given table. Dim objRs, strSQL, i, strOutput Set objRs = Server.CreateObject("ADODB.Recordset") strSQL = "SELECT * FROM " & strTable & ";" objRs.Open strSQL, t_conn, adOpenStatic, adLockReadOnly, adCmdText ' access the fields collection for this table strCNtable = "CREATE TABLE " & strNewTable & " " For i = 0 to objRs.fields.count -1 if IsNull(objRs.fields(i).definedsize) then strSizeSHow = "" else strSizeShow = "(" & objRs.fields(i).definedsize & ")" end if strCNtable = strCNtable & objRs.fields(i).name & " " & DataTypeName(objRs.fields(i).type) & strSizeShow & "," Next objRs.Close Set objRs = Nothing strTableStringSize = Len(strCNtable) strTableStringSize = strTableStringSize - 1 strCNTable = Left(strCNtable, strTableStringSize) End Sub Function DataTypeName(icurrenttype) ' this function takes an integer and translates ' it into a text based description of a data type ' that is more familiar than a number. SELECT CASE icurrenttype case 6 DataTypeName = "CURRENCY" case 3 DataTypeName = "NUMBER" case 203 DataTypeName = "MEMO" case 200 DataTypeName = "VARCHAR" case 202 DataTypeName = "TEXT" END SELECT End Function %>
--------------- -Da_Stimulator
Edited by - da_stimulator on 01 November 2001 15:58:59 |
 |
|
redbrad0
Advanced Member
    
USA
3725 Posts |
Posted - 01 November 2001 : 16:58:48
|
why dont you just create a test table and then run the script on it?
Brad |
 |
|
Da_Stimulator
DEV Team Forum Moderator
    
USA
3373 Posts |
Posted - 01 November 2001 : 17:02:45
|
refer to my 'genious' topic lol- I downloaded the database for backup (since the live one never has live users), and ran it - but there's a 'syntax' error in the create table statement
--------------- -Da_Stimulator |
 |
|
|
Topic  |
|