Ans.Database Management Systems Q2. Define the following term 1. Primary Key 2. Foreign Key 3. Candidate Key 4. Alternate Key Ans. 1. A field which uniquely identifies each and every record in table is called primary key. 2. A FOREIGN KEY is a field (or collection of fields) in one table that refers to the PRIMARY KEY in another table. It is used to link two tables. 3. Those fields which can act as a primary key are called candidates key. 4. Those fields which are candidate keys but not selected as primary key. Q3. A group of rows and columns is called _______________ Ans. Table Q4. Candidate Key – Primary key = ___________________ Ans. Alternate Key Q5. Give two examples of DBMS software. Ans. Oracle, MS Access, MySQL Q6. What is the difference between Data and Information? Ans. Raw facts and figures is called Data. Processed data is called information Q7. A primary key is one of the candidate key. (True/False) Ans. True Q8. What do you mean by degree and cardinality in DBMS? Ans. Number of rows in a table is called cardinality. Number of columns in a table is called degree. Q9. What is the alternate name of column in table? Ans. Attribute and Field Q10. What is the alternate name of row in table? Ans. Record and Tuple Q11. What do you mean by data redundancy? Ans. Duplication of data in a table is called redundancy. Q12. What do you mean by data integrity? Ans. Data integrity means maintaining accuracy and consistency of data. Q13. Expand DBMS. Ans. Database Management System Q14. Name 3 types of data models. Ans. 1. Hierarchical Data Model 2. Network Data Model 3. Relational Data Model Q15. A ___________ is a collection of logically related data. Ans. table Q16. Answer the following questions on the basis the given table. Admno Name Subject Sex Avg
1001 Amit Math M 85.5
1002 Suman English F 90
a. How many attributes are there in above table? Ans. There are 5 attributes/columns b. How many tuples are there in above table? Ans. There are 2 tuples c. What is the degree of above table? Ans. Degree – 5 d. What is the cardinality of above table? Ans. Cardinality – 2 e. Name the primary key in the table. Ans. Admno is the primary key. Q17. Write any five attributes of book entity. Ans. Book number (book_no), Book name(bname) , Book Author(b_author), subject, book price(b_price) Q18. Write any two advantages of database. Ans. Two advantages of database are: 1. Control of data redundancy 2. Improves data integrity Q19. What is the purpose of creating primary key in table. Ans. Primary key is created in table to search a particular record in tables as uniqueness helps to search record. Q20. Which field you choose as primary key out of following in “Employee” table 1. Emp_id 2. Emp_name 3. Emp_salary 4. Emp_desig Ans. Emp_id Q21. Write two advantages of SQL. Ans. It is very easy to learn It is not a case sensitive language. Q22. MySQL is an ___________Software. (open source/Proprietary) Ans. open source Q23. Name two types of SQL commands. Ans. DDL & DML Q24. What is the difference between DDL and DML Commands? Ans. DDL DML
It stands for Data Definition Language It stands for Data Definition Language
These commands allow to perform
These commands are used to manipulate tasks data related to the structure of the table Q25. Identify the DDL and DML commands from the following. 1. Create 2. Alter 3. Insert 4. Update 5. Drop 6. Delete 7. Select Ans 1. DDL 2. DDL 3. DML 4. DML 5. DDL 6. DML 7. DML Q26. What do you mean by data type? Ans. Data type refers to the type of data we are entering in the column of the table. Q27. Name two numeric data type in MySQL. Ans. Integer and Smallint Q28. Name two String Data type in MySQL. Ans. Char and Varchar Q29. Which data type is used for “Date of birth” field in Student table. Ans. Date Q30. What is the difference between Char and Varchar. Ans. Char is fixed length data type while Varchar is variable length data type. Q31. In MySQL, date values to be enclosed in { } or in single quotation marks(True/False) Ans. True Q32. ______________ is the format of date in MySQL. Ans. yyyy/mm/dd Q33. Data type of “name” field in a table is char(25). How many bytes will be occupied by values “Ram” and “Rohan Kumar”? Ans. 25 Q34. Time data type is used to store time in ________ format. Ans. hh:mm:ss Q35. Varchar is a fixed length data type.(True/False) Ans. False Q36. Name the command which is used to close MySQL. Ans. quit Q37. Which data type in MySQL is used to store logical values? Ans. Boolean Q38. Out of char, varchar and memo, which data type is used to store large amount of data? Ans. memo Q39. Which data type in MySQL is used to store images, animations, clips etc. Ans. BLOB or RAW Q40. Write the appropriate data types for the following fields. 1. DateofBirth 2. Salary 3. Name 4. Address 5. Phonenumber Ans. 1. Date 2. Any numeric data type preferable numeric or decimal. 3. Char or Varchar 4. Char or Varchar 5. Char or Numeric Q41. What do you mean by keyword in MySQL? Ans. Keyword refers to a word which has special meaning in MySQL. Q42. Identify the keyword from the following query. Select * from book; Ans. Keywords are : select and from Q43. All statements in MySQL is terminated by __________. Ans. Semicolon(;) Q44. We can create ____________ (database/tables)inside ___________(database/tables). Ans. tables, database Q45. SQL is a case sensitive language(T/F) Ans. False Q46. _________ Statement is used to show all the existing databases in server. Ans. Show databases; Q47. Which statement is used to show all existing table in database. Ans. Show tables; Q48. Write statement to open a database named “student”. Ans. use student; Q49. Name the command used to create database. Ans. Create database Q50. Write statement to create database named “book” Ans. create database book; Q51. ___________ Command is used to remove database completely. Ans. Drop Q52. Which command is used to show the structure of the table. Ans. desc or describe. Q53. Name the columns which are visible when we execute the following command. desc book; Ans. Columns are: Field, Type Null, Key, Default, Extra Q54. Write the command to create the following table : “Student” Field Name Datatype Constraint Rollno Integer (5) Primary Key Sname Varchar(30) Contactno Char(10) Not Null Ans. Create table student(Rollno integer(5) not null primary key, Sname varchar(30), Contactno char(10) not null); Q55. Write query to insert the following record in above created table. Roll number — 1, Name–Amit, Contact number– 1234567890 Ans. Insert into student values(1, “Amit”, “123456780”); Q56. Write a query to insert the following values only. Roll number — 2 , Contact number– 11111111 Ans. Insert into student(Rollno, Contactno) values(2 , ‘1111111’); Q57. Is Null value is equivalent to Zero? Ans. No Q58. What do you mean by Null in MySQL? Ans. Null means a value which is unavailable or in other words we can say Null means no value. Q59. Which command is used to modify data in table? Ans. Update Q60. Write a query to modify the Contactno to 98789878 whose roll number is 1 in table student.(given above) Ans. Update student set Contactno=’98789878′ where Rollno = 1; Q61. Which command is used to delete data from the table? Ans. Delete Q62. Which command is used to add column in a table? Ans. Alter Q63. Write a query to add the column DOB of data type date in table Student. Ans. Alter table student add DOB date; Q64. Write a query to add new column “Grade” of data type varchar(2) in table ‘Student’ with default value “A”. Ans. Alter table student add( Grade varchar(2) default “A”); Q65. Write a query to change the data type of above added column (Grade) to varchar(4). Ans. Alter table student modify (Grade varchar(4)); Q66. Write a query to delete column Grade from table student. Ans. Alter table Student drop Grade; Q67. ___________Command is used to delete table completely/permanently. Ans. Drop table Q68. Write a query to delete the table “Emp” permanently. Ans. Drop table Emp; Q69. Delete from emp; The above command will delete all the records from table “emp”. (True/False) Ans. True Q70. Write a query to display all the records from table “Student” Ans. Select * from Student; Q71. Write the output of the following: Select 76 + 75%4 from dual; Ans. 79 Write the queries of the following: Table : Student Q72. Display all the records of table student. Ans. Select * from student; Q73. Display Roll Number, Name and Class of table Student Ans. Select RollNo, Name , Class from student; Q74. Display records of students of class X. Ans. Select * from student where class = ‘X’; Q75. Display details of Sumit. Ans. Select * from student where Name = ‘Sumit’; Q76. Display records of student paying fees less than 3000. Ans. Select * from students where fee < 3000; Q77. Display fee of Amit Ans. Select fee from student where name = “Amit”; Q78. Display Class and percentage of Pushkar. Ans. Select class, percentage from student where name = “Pushkar” Q79. Delete record of Amit Ans. Delete from student where name = “Amit” Q80. Display the structure of table student Ans. Desc student; Q81. What do you mean by aggregate function? Ans. A function which work on multiple values and return a single value. Q82. Which keyword is used to arrange records in increasing or decreasing order? Ans. Order by Q83. Which function returns the total number of records in a table? Ans. Count( ) Q84. Select count( * ) from student; return 5 and Select count(fee) from student; return 4 why different output is coming in above two queries? Ans. Different output shows that there must be one null value in column fee. Q85. ____________ function return the average value of a numeric column. Ans. avg( ) Q86. Which function returns the sum of numeric column? Ans. sum( ) Q87. _______ keywords removes duplicates records from the table. Ans. distinct Q88. Write a query to display all the records of table student whose name starts from “A” Ans. Select * from student where name like “A%”; Q89. Identify the error in the following statement. Select * from student where name = null Ans. Select * from student where name is null; Q90. Which function return the minimum value from column fee of table student? Ans. min( ) Q91. What is the difference between drop and delete command? Ans. Drop command delete the data as well as structure of table permanently from database while delete command delete only the data from the table. Q92. Differentiate between Alter and Update command. Ans. Alter command is used to change the structure of table and Update command is used to modify the data of table. Q93. What is group by clause? Ans. This clause is used to arrange same data in groups using some group functions like Sum, average etc. Write the output of the following: Q94. Select 75 + 3*2 Ans. 81 Q95. Select 23 + 56%5 Ans. 24 Q96. Select power(2,3) Ans. 8 Q97 Select round(10.237,2) Ans. 10.24 Q98 Select round(12.3454,2) Ans. 12.35 Q99.Select round(12.3444,2) Ans. 12.34 Q100. Write the query on the basis of the following table : STUDENT Name, Admno, Subject, Average, Position a. Display all records in ascending order by name Ans. Select * from Student order by Name; b. Display details of students whose position is “First” and average greater than 70 Ans. Select * from student where position =”First” and Average >70;
Identify the errors in the following query
Q101 Select * from Student where Name = NULL; Ans. Select * from Student where Name is NULL; Q102 Select max(salary) from employee group by designation where DOJ > “2020-02-02”; Ans. Select max(salary) from employee group by designation having DOJ > “2020-02-02”; Q103 Select * from student where name is = “Amit”; Ans. Select * from student where name = “Amit”; Q104 Select * from employee where salary between 1000, 2000; Ans. Select * from employee where salary between 1000 and 2000; Q105. Select * from employee where name = “A%”; Ans. Select * from employee where name like “A%”; Q106. Select Name , Subject from student where average >20 and < 30; Ans. Select Name , Subject from student where average >20 and average < 30; Q107. Select * from Student where Name = “Amit” and Name =”Sumit”; Ans. Select * from Student where Name = “Amit” or Name = “Sumit”; Q108. Select highest(Salary) from employee; Ans. Select max(Salary) from employee; Q109. Select all from student; Ans. Select * from Student; Q110. Update table student set Name = “Sunita” where admno = 1234; Ans. Update student set Name = “Sunita” where admno = 1234; Write the output of the following on the basis of given Table : Product
Q111. Select max(price) from product;
Ans. 320 Q112. Select avg(price) from product; Ans. 218 Q113. Select min(qty) from product; Ans. 17 Q114. Select count(*) from product; Ans. 5 Q115. Select count(Qty) from product; Ans. 5 Q116. Select distinct(price) from product; Ans. 240 300 320 130 100 Q117. Select count(distinct(price)) from product; Ans. 5 Q118. Select price * Qty from product; Ans. 5520 7200 13760 4160 1700 Q119. Select sum(price) from product; Ans. 1090 Q120. Select sum(price) where Qty > 30; Ans. Error Q121. Write the queries of the following on the basis of given table : Faculty
i. Display details of Faculties who joins after 1990.
Ans. Select * from faculty where DOJ > “31-12-1990”; ii. Display details of Faculties whose salary is more than 20000. Ans. Select * from faculty where Fsal > 20000; iii. Show the name of faculties whose DOJ is 12-10-1980. Ans. Select Fname from faculty where DOJ = “12-10-1980”; iv. Display the detail of faculties whose name start from alphabet ‘A’. Ans. Select * from faculty where Fname like “A%”; v. Display details of faculties whose salary is greater than 25000 and name ends with ‘n’. Ans. Select * from faculty where Fsal > 25000 and Fname like “%n”; vi. Count number of faculties whose name starts with ‘S’ and salary more than 40000. Ans. Select count(*) from faculty where Fname like “S%” and Fsal > 40000; vii. Display all records in increasing order of name. Ans. Select * from faculty order by Fname; viii. Display details of faculties who earns maximum. Ans. Select *, max(Fsal) from faculty; OR Select * from faculty where Fsal = (Select max(Fsal) from faculty); ix. Display name of lowest earning faculty. Ans. Select *, min(Fsal) from faculty; OR Select * from faculty where Fsal = (Select min(Fsal) from faculty); x. Display “Annual Salary” of all faculties. (Given salary is monthly) Ans. Select Fsal * 12 as “Annual Salary” from faculty;