Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Create 100 tables in batch

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

# 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) = =

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report