Avatar billede treinholdt Nybegynder
19. december 2001 - 23:26 Der er 8 kommentarer og
1 løsning

Oprettelse af db via scripting

Hej !

Er i gang med at lave et script til oprettelse af en table, er du lige stødt ind i en lille tricky ting.

Script lyder som følger:

SQL = \"Create Table test(menu_id int, menu_count int\"

Jeg ønsker dog at sætte standardværdi til 0 samt menu_id skal være indexeret, men ikke som primær nøgle

Al hjælpe vil være stort :)
Avatar billede terry Ekspert
22. december 2001 - 15:00 #1
Create Table test(menu_id integer CONSTRAINT TheKeyName PRIMARY KEY, menu_count integer

Do you want an AUTONUMBER field as menu_id?
Avatar billede terry Ekspert
26. december 2001 - 18:00 #2
You may find this helpfull too, all you wnat to know about DAO! (NOTE: ca. 10Mb)

http://home1.stofanet.dk/santhel/Download/Jet351.zip

Avatar billede treinholdt Nybegynder
27. december 2001 - 20:15 #3
Hi,

this is great thanks alot. I decided to use ADOX before I saw this, the script underneath. Just one more question, do you know how to rename a table through ADOX ?


Dim conn
Set conn = Server.CreateObject(\"ADODB.Connection\")

conn.Open dbString

Dim tbl
Dim cat


Set tbl = Server.CreateObject (\"ADOX.Table\")
Set cat = Server.CreateObject (\"ADOX.Catalog\")
cat.ActiveConnection = conn

  With tbl
      .Name = request.form(\"table\")
      Set .ParentCatalog = cat
     
      .Columns.Append \"menu_id\", adInteger
      .Columns(\"menu_id\").Properties(\"Nullable\") = True
 
      .Columns.Append \"menu_title\", adVarWChar
      .Columns(\"menu_title\").Properties(\"Nullable\") = True
     
      .Columns.Append \"menu_body\", adLongVarWChar
      .Columns(\"menu_body\").Properties(\"Nullable\") = True
     
      .Columns.Append \"menu_authorupdate\", adVarWChar
      .Columns(\"menu_authorupdate\").Properties(\"Nullable\") = True
     
      .Columns.Append \"menu_active\", adVarWChar
      .Columns(\"menu_active\").Properties(\"Nullable\") = True
     
      .Columns.Append \"menu_oprettet\", adDate
      .Columns(\"menu_oprettet\").Properties(\"Nullable\") = True
     
      .Columns.Append \"menu_change\", adDate
      .Columns(\"menu_change\").Properties(\"Nullable\") = True

  End With

cat.Tables.Append tbl
Avatar billede terry Ekspert
27. december 2001 - 21:44 #4
In ADOX 2.6 as far as I know you can only create or delete a table (name).

here are a couple of links to ADO, hope they can help you!
http://www.w3schools.com/ado/default.asp
http://www.microsoft.com/data/ado/default.htm
Avatar billede treinholdt Nybegynder
27. december 2001 - 22:38 #5
Great,thx. Very usefull links.

As far as I have discovered you can do it using adox, but you have to copy the table with contest to a new table and delete the old. That should could do it.
Avatar billede treinholdt Nybegynder
27. december 2001 - 22:38 #6
Great,thx. Very usefull links.

As far as I have discovered you can do it using adox, but you have to copy the table with contest to a new table and delete the old. That should could do it.
Avatar billede terry Ekspert
27. december 2001 - 22:42 #7
First thanks for the points :o)

But it would be nice to be able to RENAME a table. Having to first create a table and then copy the data to it could take some time if ther is lots of data in the table.

Avatar billede treinholdt Nybegynder
28. december 2001 - 11:55 #8
No prob :)

Yep, that would be nice, theres o easy way to get around this. Happy new year :)
Avatar billede kedde65 Praktikant
11. juli 2002 - 09:40 #9
Det er faktisk ganske nemt at omdøbe en tabel vha. adox. Flg kode kan bruges til det!

Private Sub Command1_Click()
    Dim tabl As ADOX.Table
    Set tabl = New ADOX.Table
    Dim conn As ADODB.Connection
    Set conn = New ADODB.Connection
    conn.Provider = "MICROSOFT.JET.OLEDB.4.0"
    conn.ConnectionString = "D:\valgsprog.mdb"
    Dim Cat As ADOX.Catalog
    Set Cat = New ADOX.Catalog
    conn.Open
    Cat.ActiveConnection = conn
   
    Cat.Tables.Item("tmp").Name = "Hula Hopsa"
       
    conn.Close
   
    Set conn = Nothing
End Sub

først bliver tabellen tmp oprettet og herefter omdøbt til "Hula Hopsa".

VH CK
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester