Python में Databases का परिचय
Jason Myers
Co-Author of Essential SQLAlchemy and Software Engineer
update() स्टेटमेंट से काम पूरा करेंinsert() जैसा, लेकिन किस रिकॉर्ड को अपडेट करना है यह तय करने के लिए where क्लॉज़ शामिल हैvalues() क्लॉज़ में column=value पेयर के रूप में जोड़ेंfrom sqlalchemy import updatestmt = update(employees) stmt = stmt.where(employees.columns.id == 3) stmt = stmt.values(active=True)result_proxy = connection.execute(stmt) print(result_proxy.rowcount)
1
where क्लॉज़ बनाएँ जो सभी रिकॉर्ड चुने जिन्हें आप अपडेट करना चाहते हैंstmt = update(employees) stmt = stmt.where(employees.columns.active == True)stmt = stmt.values(active=False, salary=0.00)result_proxy = connection.execute(stmt) print(result_proxy.rowcount)
3
new_salary = select([employees.columns.salary]) new_salary = new_salary.order_by( desc(employees.columns.salary)) new_salary = new_salary.limit(1)stmt = update(employees)stmt = stmt.values(salary=new_salary)result_proxy = connection.execute(stmt)print(result_proxy.rowcount)
3
select() स्टेटमेंट उपयोग करता हैPython में Databases का परिचय