>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