基于校友管理平台的工程学院数据解决方案
CREATE TABLE alumni (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
contact VARCHAR(150),
graduation_year YEAR,
major VARCHAR(100)
);
]]>
SELECT * FROM alumni WHERE graduation_year = 2010;
]]>
UPDATE alumni SET contact = 'new_email@example.com' WHERE id = 1;
]]>
import pymysql
def update_contact(user_id, new_contact):
connection = pymysql.connect(host='localhost',
user='root',
password='password',
db='alumni_db')
try:
with connection.cursor() as cursor:
sql = "UPDATE alumni SET contact=%s WHERE id=%s"
cursor.execute(sql, (new_contact, user_id))
connection.commit()
finally:
connection.close()
]]>
本站知识库部分内容及素材来源于互联网,如有侵权,联系必删!