Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to add Table to MSDE Database
Message
 
To
05/11/2003 11:11:21
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00846527
Message ID:
00846577
Views:
76
Cetin - thanks a bunch - this is what I needed!

Does dosya = table?:-)

>>A project requires reading some SQL 2000 data. I want to test some ideas with my MSDE license.
>>
>>I guess the driver is SQL Server - SQLCONNECT() returns a 1 - but I am a fish out of water without the Administrator.
>>
>>I've read-up on wiki and MSDN - but could not locate infor on how to create a table and add it to my MSDE (SQL Server) datatbase.
>>
>>Any pointers appreciated!
>
>Create table ...
>Alter table ...
>etc SQL commands work :)
>
>If you don't mind Turkish words in code here is a sample :
>
>
>Local lnHandle, lcDatabaseName
>lcDatabaseName = "myTestData"
>lnHandle=SQLStringConnect('DRIVER=SQL Server;'+;
>    'SERVER=servername;Trusted_connection=Yes')
>If SQLExec(lnHandle, "create database "+lcDatabaseName) < 0
>  Do errHand
>  Return
>Endif
>mySQLExec(lnHandle, "use "+lcDatabaseName)
>mySQLExec(lnHandle, ;
>  "create table anadosya"+;
>  " (malid int not null, grupid int not null, grupad varchar(10),"+;
>  "  inserttime datetime default getdate(),insertedby nvarchar(256) default suser_sname(),"+;
>  "  updatetime datetime null, updatedby nvarchar(256) null,"+;
>  "  deletetime datetime null, deletedby nvarchar(256) null)")
>mySQLExec(lnHandle, ;
>  "create table grupdosya"+;
>  " (grupId int not null IDENTITY PRIMARY KEY,"+;
>  "   grupad varchar(30))")
>mySQLExec(lnHandle, ;
>  "CREATE TABLE MalDosya"+;
>  "   (malid int NOT NULL IDENTITY PRIMARY KEY,"+;
>  "   Mal_Ad varchar(30),"+;
>  "   GrupID int NOT NULL References GrupDosya(GrupId))")
>
>mySQLExec(lnHandle, ;
>  "CREATE trigger MalDosya_Insert On MalDosya For Insert as"+;
>  "  insert into AnaDosya "+;
>  " select mal.identitycol as MalId, mal.grupId as GrupId, grup.GrupAd as GrupAd,"+;
>  " getdate(),SUSER_SNAME(),null,null,null,null"+;
>  "   from maldosya mal "+;
>  "   inner join grupdosya grup"+;
>  "   on mal.grupid = grup.grupid"+;
>  "   where mal.identitycol = IDENT_CURRENT('MalDosya')")
>
>mySQLExec(lnHandle, ;
>  "CREATE trigger MalDosya_Update On MalDosya For Update as"+;
>  "    update AnaDosya "+;
>  "      set UpdateTime = getdate(), UpdatedBy = SUSER_SNAME()"+;
>  "      where exists (select * from inserted where Anadosya.MalId = inserted.MalId)")
>
>mySQLExec(lnHandle, ;
>  "CREATE trigger MalDosya_Delete On MalDosya For Delete as"+;
>  "  update AnaDosya "+;
>  "      set DeleteTime = getdate(), DeletedBy = SUSER_SNAME()"+;
>  "      where exists (select * from deleted where Anadosya.MalId = deleted.MalId)")
>
>
>* Tablo ve trigger hazir
>* Grup tanimla
>For jx=1 to 5
>  m.lcGrupAd = 'Grup'+trans(jx)
>  mySQLExec(lnHandle, "insert into GrupDosya (grupad) values (?lcGrupAd)") && Grup
>Endfor
>
>* Mal insert
>mySQLExec(lnHandle, "select * from GrupDosya","crsGrup")
>Select crsGrup
>Scan
>  m.luGrupID = crsGrup.GrupId
>  For ix=1 to 3
>    m.lcMalAd  = trim(crsGrup.GrupAd)+'_Mal'+trans(ix)
>    mySQLExec(lnHandle, "insert into MalDosya (Mal_Ad, GrupId) values (?lcMalAd, ?luGrupId)")
>  Endfor
>Endscan
>
>* Insert sonrasi ne insert edildigine bak
>CheckTables(lnHandle,'Insert sonrasi')
>
>mySQLExec(lnHandle, "update MalDosya set GrupId = 3 where GrupId = 2")
>
>* Guncelleme sonrasi
>CheckTables(lnHandle,'Guncelleme sonrasi')
>
>mySQLExec(lnHandle, "delete from MalDosya where GrupId = 3")
>
>* Delete sonrasi
>CheckTables(lnHandle,'Delete sonrasi')
>
>SQLDisconnect(lnHandle)
>
>Function mySQLExec
>Lparameters tnHandle, tcSQL, tcCursorName
>tcCursorName = iif(empty(tcCursorName),'',tcCursorName)
>If SQLExec(tnHandle,tcSQL,tcCursorName) < 0
>  Do errHand with tcSQL
>Endif
>
>Function errHand
>Lparameters tcSQL
>lcError=tcSQL+chr(13)
>Aerror(arrCheck)
>For ix=1 to 7
>  lcError = lcError+trans( arrCheck [ix])+ chr(13)
>Endfor
>Messagebox(lcError,0,'Error def.')
>
>
>Function CheckTables
>Lparameters tnHandle,tcTitle
>mySQLExec(tnHandle, ;
>  "select * from GrupDosya; select * from MalDosya ; select * from AnaDosya","crsResult")
>
>Select crsResult
>Browse title 'Gruplar - '+tcTitle
>Select crsResult1
>Browse title 'Mallar - '+tcTitle
>Select crsResult2
>Browse title 'Ana - '+tcTitle
>
Cetin
Imagination is more important than knowledge
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform