Avatar billede skaanning Seniormester
05. oktober 2015 - 16:01 Der er 20 kommentarer og
1 løsning

SQL i Acces

Hej er der en der ved om man kan få vist det SQL der ligger bag de tabeller der er oprettet?
Avatar billede terry Ekspert
05. oktober 2015 - 17:11 #1
As far as I know it isn't possible in Access but you may be able to find utilities which may do what you want.

For example https://bitbucket.org/himselfv/jet-tool/wiki/Home
Look under downloads.

Maybe a silly question but why do you need the sql?
Avatar billede terry Ekspert
05. oktober 2015 - 17:13 #2
Avatar billede skaanning Seniormester
05. oktober 2015 - 19:27 #3
Because i am a student in SQL and I can only use Access if I build my DB in SQL, I can do that but there are some code lines that Access wont accept`, so I thought if I make it the normal way in Access and then look at the code then I could see the right way to do it.
I have looked at the Jet but i can not run it in Windows 10 - is there a problem with that ?
Avatar billede terry Ekspert
06. oktober 2015 - 09:52 #4
OK, I went back to take a look at your previous question where you were having problems with executing your SQL.

So I've made a bit of code to show you how you can execute your SQL without errors, hopefully anyway.

You need to create a module in Access.


Public Function ExecuteSQL() As Boolean
Dim sSQL As String

    On Error GoTo Err
   
    sSQL = "CREATE TABLE telefon (tlf varchar(50), personid int, primary key(tlf, personid), foreign key (personid) references person(id) on delete cascade);"
   
    'DoCmd.RunSQL sSQL                                  'Will fail
    'CurrentDb.Execute sSQL                            'Will also fail
    CurrentProject.Connection.Execute sSQL              'ADO methed which will work.
   
   
ExitFunction:
    Exit Function

Err:
    MsgBox Err.Number & vbCrLf & Err.Description
   
End Function
Avatar billede terry Ekspert
06. oktober 2015 - 09:52 #5
This works with Windows 10 Access 2013
Avatar billede skaanning Seniormester
06. oktober 2015 - 11:26 #6
alright where do I type i in under vba or what, an how do I execute it?
Avatar billede terry Ekspert
06. oktober 2015 - 11:42 #7
https://www.youtube.com/watch?v=pqxoZTS5tBQ

You can then copy my example into the module.
Avatar billede terry Ekspert
08. oktober 2015 - 14:25 #8
Are you still having problems?
Avatar billede skaanning Seniormester
10. oktober 2015 - 06:58 #9
yes i still  have problems, when I try the vba code you made, I get an error saying that it don't find a specific index for the field that refers to in the primary tabel I have tried to compare, and I thinks i looks right.

Ups - now I found it !  I haven't made a Primary key in person; So yes now I am on line again thanks to you:))
Avatar billede terry Ekspert
10. oktober 2015 - 09:58 #10
Great, have a good weekend. Oh, please accept my answer if your happy with it :-)
Avatar billede terry Ekspert
11. oktober 2015 - 17:53 #11
Thanks
Avatar billede skaanning Seniormester
13. oktober 2015 - 10:07 #12
hi I don't now if you vill help me again, but I trait to create new person tabel with the same vba syntax as you show me, but it ditten funktion, it looks like as it is the sentence "GENERATED BY DEFAULT AS IDENTITY" do you have an idea?

CREATE TABLE person (id int GENERATED BY DEFAULT AS IDENTITY, startdato date, slutdato date not null, navn varchar(50) not null, gade varchar(50) not null, postnr int references postnummer (postnr), email varchar(80), PRIMARY KEY(id, startdato));
Avatar billede terry Ekspert
13. oktober 2015 - 10:43 #13
I'll have a look and get back to you ASAP, bit busy right now.
Avatar billede terry Ekspert
13. oktober 2015 - 10:50 #14
I'm not at all sure that it is valid SQL your trying to execute.

Try
CREATE TABLE Person(ID AUTOINCREMENT ...
Avatar billede skaanning Seniormester
13. oktober 2015 - 11:30 #15
Yes it work, but why do I have to close an open access before I can see the new tabel?
Avatar billede terry Ekspert
13. oktober 2015 - 12:34 #16
No idea, but if you just press the save button it also shows table
Avatar billede terry Ekspert
13. oktober 2015 - 12:36 #17
Just for your information. I have made a form where I can enter the SQL then a button calls the code which executes the SQL.

Not very fancy but it saves having to change code .

If you are interested I could send it
Avatar billede skaanning Seniormester
13. oktober 2015 - 14:39 #18
Yes thanks I would like that can it also be used to insert code or select osv.
Avatar billede skaanning Seniormester
13. oktober 2015 - 14:43 #19
I have made this in a Query but want work
INSERT INTO person
(STARTDATO, SLUTDATO, NAVN, GADE, POSTNR, EMAIL )
VALUES ('2015-09-01' , '2015-12-01', 'Hans Iversen', 'Den ene vej', 7400, 'hi@eamv.dk');
Avatar billede skaanning Seniormester
13. oktober 2015 - 15:27 #20
hi if you vil send it to me, me mail is pesk@vestas.com
Avatar billede terry Ekspert
13. oktober 2015 - 15:45 #21
I've sent the dB.

The insert looks OK from here, dont you get an error with some information as to what is wrong?
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

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