Get the App
SLTechnology News&Howtos  ›  Database  › 

Create 100 tables in batch

Shulou Source: shulou.com Published: 2022-06-01 08:54:48 11月18日 Update

# at work, there is often the need to create n tables named after time or numbers. # here are four commonly used small scripts for creating 100 tables in batches. # result mysql > show tables +-+ | Tables_in_tsdb | +-+ | Total_Winner_01 | | Total_Winner_02 | | Total_Winner_03 | | Total_Winner_04 | | Total_Winner_05 | | Total_Winner_06 | | Total_Winner_07 | | Total_Winner_08 | | Total_Winner_09 | | Total_Winner_10 | | Total_Winner_11 | | Total_Winner_12 | | Total_Winner_13 | | | Total_Winner_14 | | Total_Winner_15 | +-+ 15 rows in set (0.00 sec) # the first is: # # create 100 tablespace binder RenmaiInfluenceDB'for i in {0 99} Do len= `expr length $i`if [$len-eq 2]; then num=$ielse num= "0 ${I}" fi echo 'CREATE TABLE `Total_Winner_'''$num'''' (`Id` INT (10), `UserId` INT (10), PRIMARY KEY (`Id`) ENGINE = INNODB DEFAULT CHARSET = utf8 The second type of echo done=#: #! / bin/sh#creat tablesfor i in `seq 1 15`do var= `printf "d\ n" $i`echo''CREATE TABLE `Total_Winner_'''$var''' `(`Id` INT (10), `UserId` INT (10), PRIMARY KEY (`Id`)) ENGINE = INNODB DEFAULT CHARSET = utf8 The third type of echodone====#: #! / bin/sh # you need to delete the "`" symbol in SQL from for i in `seq 01.99`do STEP= `printf d ${I} `create_tab_sql= "CREATE TABLE Total_Winner_$ {STEP} (Id INT (10), UserId INT (10), PRIMARY KEY (Id)) ENGINE = INNODB DEFAULT CHARSET = utf8 "echo-e ${create_tab_sql} echodone====# IV: Python script #! / usr/bin/pythonimport stringfor i in range (7Magne13): sql =" CREATE TABLE `Content_ 2015d` LIKE `Content_ 201503`; "% I print (sql) for i in range (15Yue20): sql =" CREATE TABLE `Content_ 2016d` LIKE `Content_ 201503`; "% I print (sql) = =

Tags: Scripts frequent meetings frequently used numbers times symbols results requirements work Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Technology NVidia OPPO Reno Shulou Information