0% found this document useful (0 votes)
4 views1 page

Python and SQL Exercises for Beginners

Uploaded by

ts4521225
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Python and SQL Exercises for Beginners

Uploaded by

ts4521225
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1) Write a python program to create a CSV file by entering user-id and password, read and

search the password for given user-id. 8


2) Create a table students with six attributes (Roll, Name, Age, Class, Email ,Phone) that
contains minimum 3 tuples. Then write the following SQL queries - 4
a) Modify Email of student whose roll is 1099.
b) Print the name of youngest student.
c) Print the table of students from higher class to lower class.
d) Delete the column Phone from table
1) Write a python program to create a binary file with name and roll number. Search for a
given roll number and display the name, if not found display appropriate message. 8
2) Create a table employee with six attributes (Empid, Name,Designation, Email,Phone,Salary)
that contains minimum 3 tuples. Then write the following SQL queries - 4
a) Print total no of clerk present in table.
b) Print the name and designation of employees whose name contains ‘a’.
c) Print average salary of employees.
d) Change data type of Phone.
1) Write a python program to read a text file and display the number of vowels,consonants,
lowercase and uppercase characters in the file. 8
2) Create a table employee with six attributes (Empid, Name,Designation,DOB,Phone,Salary)
that contains minimum 3 tuples. DOB attribute cannot contain null value. Then write the
following SQL queries - 4
a) Print name and designation of employee whose salary is more than 50000.
b) How many different posts are present in employee table.
c) Delete the primary key(Empid) from table.
d) Make Phone as primary key
1) Write a Python program to implement push and pop operation of a stack using list. 8
2) Create a table students with six attributes (Roll, Name,DOB, Class, Email ,Phone)that
contains minimum 3 tuples. DOB attribute cannot contain null value. Then write the
following SQL queries - 4
a) Change Email of a student named ‘Atul’.
b) Print different class present in table.
c) Add a new column Marks to the table.
d) Delete the details of all class X students.

Common questions

Powered by AI

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 .

You might also like