Python and SQL Exercises for Beginners
Python and SQL Exercises for Beginners
To update the email of a student with a specific roll number, you would use the SQL UPDATE statement as follows: UPDATE students SET Email = 'new_email' WHERE Roll = 1099 .
Stacks are useful for problems that involve recursive data processing or need history tracking, such as parsing expressions and function call management. In Python, stacks can be implemented using lists, where the append() method performs the push operation and pop() removes the last element .
The SQL query to retrieve names and designations of employees earning more than 50000 would be: SELECT Name, Designation FROM employee WHERE Salary > 50000 .
Firstly, use ALTER TABLE to add a new column: ALTER TABLE students ADD Marks INT. Then, to delete details of a specific class, use the DELETE FROM statement: DELETE FROM students WHERE Class = 'X' .
You can use Python's built-in CSV module to create a CSV file. First, take user inputs for user-id and password and write these into the CSV file using the csv.writer object. To search for a password, read the CSV file using csv.reader, iterate through the rows to find the specified user-id, and return the corresponding password if found .
Making a column a primary key enforces uniqueness and non-nullability. It also creates a clustered index which can significantly speed up queries that search for records by that column, but might slow down data insertion and updates due to index maintenance overhead .
The Python program should first open the binary file using open() in binary read mode. Use the pickle module to deserialize objects. Iterate through the file and use a condition to compare each roll number. If the roll number matches, display the associated name; if not found, output an appropriate message .
Use the ALTER TABLE command along with MODIFY/MODIFY COLUMN to change the data type of a column. For example: ALTER TABLE employee MODIFY Phone BIGINT. This change might be necessary to expand the range of phone numbers or conform to a standardized format .
Open the text file using open() with read mode. Read the content into a string and iterate through each character, using conditional checks and counters to count vowels, consonants, uppercase, and lowercase letters. Utilize string methods to check for each character type .
Use the COUNT(DISTINCT) function in SQL to find the number of different job titles: SELECT COUNT(DISTINCT Designation) FROM employee .