1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| Sub CreateNewMDBSQL()
'***************************************************************************
'Création de la base de données bilan
'***************************************************************************
'Déclaration
Dim cnn As Object
Dim cat As Object
'Initialisation
Set cnn = CreateObject("ADODB.Connection")
Set cat = CreateObject("ADOX.Catalog")
'Création de la base de données Bilan.accdb
cat.Create "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & ThisWorkbook.Path & "\Bilan.accdb; Mode =" & adModeShareExclusive
Set cnn = cat.ActiveConnection
'Création de la table Files
cnn.Execute "CREATE TABLE t_Files (FileId int NOT NULL IDENTITY(1, 1) PRIMARY KEY," _
& "Path varchar(255) NOT NULL," _
& "Name varchar(8) NOT NULL," _
& "DateLastModified datetime NOT NULL," _
& "UpdateRequired bit DEFAULT True," _
& "Excluded bit DEFAULT False," _
& "CONSTRAINT chk_FileExist UNIQUE (Path,Name)," _
& "CONSTRAINT chk_FileName CHECK (Name LIKE '[Ss][0-5][1-9].xlsm')," _
& "CONSTRAINT chk_DateLastModified CHECK (DateLastModified >= #01/01/2017# AND DateLastModified <= date()))", adCmdText + adExecuteNoRecords
'Création de la table Imputation
cnn.Execute "CREATE TABLE t_Imputation (Id int NOT NULL IDENTITY(1, 1) PRIMARY KEY," _
& "FilePath varchar(255) NOT NULL," _
& "FileName varchar(8) NOT NULL," _
& "'Year' int NOT NULL," _
& "Week int NOT NULL," _
& "ProjectNumber varchar(6) NULL," _
& "ProjectElement varchar(6) NULL," _
& "TacheCode varchar(3) NULL," _
& "Imputation decimal(2,2) NOT NULL," _
& "CONSTRAINT fk_FilePath_FileName FOREIGN KEY (FilePath, FileName) REFERENCES t_Files(Path, Name) ON DELETE CASCADE ON UPDATE NO ACTION," _
& "CONSTRAINT chk_ProjectNumber CHECK (ProjectNumber LIKE '[0-9][0-9][0-9][0-9][0-9][0-9]')," _
& "CONSTRAINT chk_ProjectElement CHECK (ProjectElement IN ('IMP01','ETU01','ETU02','ETU03','ETU05','DEPL01','CHA02','ATE01','SYCN01','SYDE01'))," _
& "CONSTRAINT chk_TacheCode CHECK (TacheCode IN ('30','75','150','V','JS','VT','X','VX')))", adCmdText + adExecuteNoRecords
cnn.Close
Set cat = Nothing
Set cnn = Nothing
End Sub |
Partager