import pymysql
#1.创建学生表,插入两条数据
#数据库连接
conn=pymysql.connect(host='localhost',user='root',password="123456789",db='world')
cursor=conn.cursor()
# create_sql='''create table student (sid char(10),sname varchar(20),ssex varchar(2));'''
# cursor.execute(create_sql)
#2.向表中插入两条数据
# insert_sql='''insert into student(sid,sname,ssex)values('003','lze','nv')'''
# cursor.execute(insert_sql)
#提交到数据库里面
conn.commit()
#3.查询表中的数据
# select_sql='''select * from student;'''
# cursor.execute(select_sql)
# print(cursor.fetchall())
#4.修改表中数据
#将学号为002的学生姓名改为lucy
# update_sql='''update student set sname='lucy' where sid=%s'''
# cursor.execute(update_sql,'002')
# conn.commit()
#删除表数据
delete_sql='delete from student where sname=%s'
cursor.execute(delete_sql,('iu'))
select_sql='''select * from student;'''
cursor.execute(select_sql)
print(cursor.fetchall())
conn.close()
© 版权声明
THE END
暂无评论内容