不带分区版本:V1.0:
Sub createTableDDL() ‘自动创建建表语句 ‘定义换行和TAB Ln = Chr(13) + Chr(10) TB = Chr(9) ‘定义脚本目录 Dim dir AS String dir = "C:\CREATE_TABLE_DDL" Set FSOE = CreateObject("Scripting.FileSystemObject") If FSOE.folderexists(dir) = False Then MkDir dir End If ‘调用脚本定义 Set SqlFileDDL = FSOE.CreateTextFile("C:\CREATE_TABLE_DDL\create_table_ddl.sql", True) ‘获得表名 tableName = Trim(Cells(1, 2).Value) ‘获得表注释 tableComment = Trim(Cells(1, 4).Value) ‘获得创建者 createBy = Trim(Cells(1, 6).Value) Dim dt As Date dt = Format(Date, "yyyy-mm-dd") ‘获得当前日期 createDate = dt ‘获得A列已使用的行数 count_row_k = [A65536].End(xlUp).Row ‘定义SQL SQL = "--创建者:" & createBy & Ln SQL = SQL & "--创建时间:" & createDate & Ln SQL = SQL & "DROP TABLE IF EXISTS " & tableName & " ;" & Ln SQL = SQL & "CREATE TABLE " & tableName & "(" ‘写入文件 SqlFileDDL.WriteLine (SQL) For i = 3 To count_row_k If i = count_row_k Then col_name = TB & LCase(Cells(i, 2)) & " " & UCase(Cells(i, 4)) & " COMMENT ‘" & Trim(Cells(i, 3)) & "‘" & Ln & ")" SqlFileDDL.WriteLine(col_name) Exit For End If col_name = TB & LCase(Cells(i, 2)) & " " & UCase(Cells(i, 4)) & " COMMENT ‘" & Trim(Cells(i, 3)) & "‘," SqlFileDDL.WriteLine(col_name) Next SqlFileDDL.WriteLine("COMMENT ‘" & tableComment & "‘") MsgBox("生成成功!生成路径为:" & dir) End Sub
原文地址:https://www.cnblogs.com/jiangbei/p/9360434.html
时间: 2024-10-25 19:05:22