Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Re-Naming a database table??
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 01 November 2001 :  14:44:52  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
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  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
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
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 01 November 2001 :  15:13:16  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
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
Go to Top of Page

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 01 November 2001 :  15:24:23  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
thats what I am using, cant edit table names though.

---------------
-Da_Stimulator
Go to Top of Page

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 01 November 2001 :  15:27:33  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
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
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 01 November 2001 :  15:29:27  Show Profile
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.
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 01 November 2001 :  15:34:42  Show Profile
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.
Go to Top of Page

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 01 November 2001 :  15:36:06  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
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
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 01 November 2001 :  15:49:09  Show Profile
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
Go to Top of Page

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 01 November 2001 :  15:58:02  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
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
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 01 November 2001 :  16:58:48  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
why dont you just create a test table and then run the script on it?

Brad
Go to Top of Page

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 01 November 2001 :  17:02:45  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
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
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.21 seconds. Powered By: Snitz Forums 2000 Version 3.4.07