第八周 第 3 節 Mysql 基礎(六)

2021-10-25 15:10:09 字數 1521 閱讀 4476

執行sql語句

@clock_it_deco

def insert_many():

values =

for i in range(10**4):

store_name = f"店鋪_"

amount = format(random.uniform(10**3, 10**6), '.2f')

department = f"事業部_"

sta_date = time.strftime("%y-%m-%d")

sql = """insert into store_perf(store_name, amount, department, sta_date)

values (%s, %s, %s, %s)"""

print(values)

mysql_cursor.executemany(sql, values)

mysql_con.commit()

獲取返回值

def get_shops():

sql = "select store_name, amount, sta_date from store_perf where department='事業部_1' limit 2"

mysql_cursor.execute(sql)

# 獲取返回值

query_set = mysql_cursor.fetchall()

print(query_set)

create index 索引名 on 表名(欄位1, 欄位2...)

create index store_name_index on store_perf(store_name)

建立聯合索引

create index store_name_sta_date_department_index on store_perf(store_name, sta_date, department)

檢視索引

show index from store_perf

刪除索引

alter table store_perf drop index  store_name_index

檢視當前查詢語句有沒有命中索引

explain select * from store_perf where store_name = "店鋪_224123"

單個字段可以命中聯合索引嗎?

聯合索引涉及到乙個叫左綴查詢的規則

如果想命中索引, 查詢語句中涉及到字段必須是聯合索引建立時從左到右順序

索引的實現原理

b+樹, 一種特殊的鍊錶, 用來實現二分查詢.

加快取換固態硬碟

第八周實驗報告3

includeusing namespace std class cfraction cfraction cfraction int nu,int de nume nu deno de void cfraction set int nu,int de void cfraction input els...

第八周 OJ總結 3 求值

煙台大學計算機與控制學院 all ringts reserved.檔名稱 oj總結 3 求值 作 者 王興振 完成日期 2016年10月24日 版 本 號 未知 題目描述 求sn 1 2 3 4 5 n 之值,其中n是乙個數字。輸 入 n輸 出 和樣例輸入 樣例輸出 提 示 資料型別 long lo...

第八周實踐專案3 順序串演算法

1.標頭檔案 sqstring.h,包含定義鏈隊資料結構的 巨集定義 要實現演算法的函式的宣告 define maxsize 100 最多的字元個數 typedef struct sqstring void strassign sqstring s,char cstr 字串常量cstr賦給串s vo...