Excel自動生成sql建表語句

2021-06-22 16:50:18 字數 2508 閱讀 8066

sub 生成目錄()

'生成表目錄

for si = 2 to workbooks(1).sheets.count '從第二張表開始,遍歷每一張表

set mysheet = workbooks(1).sheets(si) '表

workbooks(1).sheets(1).range("d" & si).value = mysheet.name '中文名

workbooks(1).sheets(1).range("d" & si).hyperlinks.add anchor:=workbooks(1).sheets(1).range("d" & si), address:="", subaddress:="'" & mysheet.name & "'!r1c1"

workbooks(1).sheets(1).range("c" & si).value = mysheet.range("a2").value '英文名

workbooks(1).sheets(1).range("a" & si).value = si - 1 '序列

next si

end sub

sub 生成sql()

'生成建表hql

dim sql as string

dim tablename as string

dim comm as string

for si = 2 to workbooks(1).sheets.count '從第二張表開始,遍歷每一張表

set mysheet = workbooks(1).sheets(si) '表

tablename = mysheet.range("a2").value '英文表名

'如果資料庫中已存在表,則刪除表

'if exists (select * from sysobjects where name='tablename')

'sql = sql & "if exists (select * from all_tables where name='" & tablename & "') " & vbcrlf

'drop table tablename

sql = sql & "drop table " & tablename & " ;" & vbcrlf

'sql = sql & "go " & vbcrlf

'開始建立表

'create table tablename (

sql = sql & "create table " & tablename & " ( " & vbcrlf

comm = ""

for i = 2 to mysheet.usedrange.rows.count '遍歷所有的列

dim namestr as string

dim typestr as string

namestr = mysheet.range("b" & i).value '欄位名

typestr = mysheet.range("d" & i).value '資料型別

refstr = mysheet.range("e" & i).value '是否主鍵

commstr = mysheet.range("c" & i).value '中文注釋

if refstr = "是" then

sql = sql & " " & namestr & " " & typestr & " primary key" '預設id為主鍵

else

sql = sql & " " & namestr & " " & typestr '非id列,則直接加入

end if

if len(commstr) > 0 then

comm = comm & vbcrlf & "comment on column " & tablename & "." & namestr & " is " & "'" & commstr & "';"

end if

if i < mysheet.usedrange.rows.count then

sql = sql & "," '新增『,』號

end if

sql = sql & vbcrlf

next i

'建表完成

sql = sql & ")" & vbcrlf

sql = sql & "tablespace jfxtdata pctfree 10 initrans 1 maxtrans 255 storage ( initial 64k next 1m minextents 1 maxextents unlimited ) ;" & vbcrlf

sql = sql & comm & vbcrlf & "-----create table " & tablename & " end." & vbcrlf & vbcrlf

next si

sheets("目錄").txtconsole.text = sql

end sub

ssh架構不能自動生成建表語句

使用的annotation 在spring配置檔案中配置了hbm2ddl.auto,發布正常,但就是沒有自動建表,沒有任何提示,搜了搜無意發現是很細節的問題。org.hibernate.dialect.mysqldialect true create 20thread org.hibernate.t...

SQL建表語句 約束

create table stu id number 6 name varchar2 20 constrait stu name nn not null,constraint約束 字段約束 number 1 age number 3 sdate date,grade number default 1...

批量生成hive建表語句

這裡以shell為例 bin bash db dim echo 匯出資料庫所有的表結構 hive e use db show tables root migration db tables.txt echo 迴圈遍歷表名 cat root migration db tables.txt while ...