टेबल में डेटा अपडेट करना

Python में Databases का परिचय

Jason Myers

Co-Author of Essential SQLAlchemy and Software Engineer

टेबल में डेटा अपडेट करना

  • update() स्टेटमेंट से काम पूरा करें
  • insert() जैसा, लेकिन किस रिकॉर्ड को अपडेट करना है यह तय करने के लिए where क्लॉज़ शामिल है
  • जिन मानों को अपडेट करना है, उन्हें values() क्लॉज़ में column=value पेयर के रूप में जोड़ें
Python में Databases का परिचय

एक पंक्ति अपडेट करना

from sqlalchemy import update

stmt = update(employees) stmt = stmt.where(employees.columns.id == 3) stmt = stmt.values(active=True)
result_proxy = connection.execute(stmt) print(result_proxy.rowcount)
1
Python में Databases का परिचय

एकाधिक पंक्तियाँ अपडेट करना

  • ऐसा where क्लॉज़ बनाएँ जो सभी रिकॉर्ड चुने जिन्हें आप अपडेट करना चाहते हैं
Python में Databases का परिचय

एकाधिक पंक्तियाँ जोड़ना

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
Python में Databases का परिचय

संबद्ध अपडेट्स

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
Python में Databases का परिचय

संबद्ध अपडेट्स

  • जिस कॉलम को हम अपडेट कर रहे हैं, उसका मान ढूँढने के लिए select() स्टेटमेंट उपयोग करता है
  • सामान्यतः अधिकतम मान पर रिकॉर्ड अपडेट करने या किसी स्ट्रिंग को दूसरी टेबल के संक्षेप से मैच कराने के लिए उपयोग होता है
Python में Databases का परिचय

अभ्यास करते हैं!

Python में Databases का परिचय

Preparing Video For Download...