sql常用 语句总结
Posted chaojiyingxiong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql常用 语句总结相关的知识,希望对你有一定的参考价值。
一,插入一个新字段:ALTER TABLE +表名+ADD COLUMN(字段名+ 类型)
sql1 = ‘ALTER TABLE klkl_4s_shop ADD COLUMN (name_real VARCHAR(100) DEFAULT NULL ,registered_capital VARCHAR(100) DEFAULT NULL,register_time VARCHAR(100) DEFAULT NULL,approved_time VARCHAR(100) DEFAULT NULL,industry_num VARCHAR(100) DEFAULT NULL,company_state VARCHAR(100) DEFAULT NULL,creditcode VARCHAR(100) DEFAULT NULL,organizationcode VARCHAR(100) DEFAULT NULL,capital_real VARCHAR(100) DEFAULT NULL,staff_size VARCHAR(100) DEFAULT NULL,insurance_num VARCHAR(100) DEFAULT NULL,company_type VARCHAR(100) DEFAULT NULL,period VARCHAR(100) DEFAULT NULL,trade VARCHAR(100) DEFAULT NULL,business_adress VARCHAR(100) DEFAULT NULL,bussness_scope VARCHAR(100) DEFAULT NULL)‘
二,更新数据: UPDATE +表名+SET +字段 = 值
sql2 = "UPDATE klkl_Service_shop SET name_real = ‘{}‘ ,registered_capital = ‘{}‘,industry_num = ‘{}‘,company_state = ‘{}‘,creditcode = ‘{}‘,organizationcode = ‘{}‘,capital_real = ‘{}‘,staff_size = ‘{}‘,insurance_num = ‘{}‘,company_type = ‘{}‘,trade = ‘{}‘,adress = ‘{}‘,bussness = ‘{}‘WHERE id = ‘{}‘".format(name_real, registered_capital, industry_num, company_state, creditcode, organizationcode, capital_real,staff_size, insurance_num, company_type, trade, adress, bussness,result[1])
三,插入一条新数据:INSERT INTO +表名 + 字段 + values +值
sql = ‘insert into klkl_4s_shop(city,district,company_name,business,phone,adress) values (%s,%s,%s,%s,%s,%s)‘
四:从数据库中获取某一列的值:cursor.fetchmany()
coon = pymysql.connect(host=‘*****‘, user=‘root‘, password=‘******‘, port=****, db=‘0000‘) #二,创建游标 cursor = coon.cursor() #三,执行查询语句 cursor.execute(‘select company_name,id from klkl_4s_shop‘) #四,获取查询结果 results= cursor.fetchmany(50) #打印结果 for result in results: print(result[0]) print(result) print(result[1])
以上是关于sql常用 语句总结的主要内容,如果未能解决你的问题,请参考以下文章