Some of the advantages of Views are
22. What is a relationship and what are they?
Database Relationship is defined as the connection between the tables in a database. There are various database relationships namely
1. One to One Relationship
2. One to Many Relationship
3. Many to One Relationship
4. Self-Referencing Relationship
23. What is a query?
A database query is a request for data or information from a database table or combination of tables. A database query can be either a select query or an action query.
24. What is a Subquery?
A Subquery is a SQL query within another query. It is a subset of a Select statement whose return values are used in filtering the conditions of the main query.
25. What are the types of subquery?
There are two types of subquery:
1. Correlated: In a SQL database query, a correlated subquery is a subquery that uses values from the outer query in order to complete. Because a correlated subquery requires the outer query to be executed first, the correlated subquery must run once for every row in the outer query. It is also known as a synchronized subquery.
2. Non-Correlated: A Non-correlated subquery is a subquery in which both outer query and inner query are independent to each other.
26. What is Synchronized Subquery?
Refer Correlated Subquery.
27. What is the difference between Local Variables and Global Variables?
Local Variables: Local variables can be used or exist only inside the function. These variables are not used or referred by any other functions. These are not known to other functions. Variables can be created whenever that function is called.
Global Variables: Global variables can be used or exist throughout the program. Same variable declared in global cannot be used in functions. Global variables cannot be created whenever that function is called.
28. What is data Integrity?
Data integrity defines the accuracy and consistency of the data stored in a database. It also defines integrity constraints to enforce business rules on the data when it is entered into an application or a database.
29. What is Auto Increment in SQL?
It is one of the important Oracle DBA Interview Questions.
Auto increment keyword allows the user to create a unique number to get generated when a new record is inserted into a table. Auto increment keyword can be used whenever Primary Key is used.
AUTO INCREMENT keyword is used in Oracle and IDENTITY keyword is used in SQL Server.
30. What is a temp table?
Ans. A temp table is a temporary storage structure to store the data temporarily.
31. How to avoid duplicate records in a query?
The SQL SELECT DISTINCT query is used to return only unique values. It eliminates all the duplicated values.
View Detailed Post
32. What is the difference between Rename and Alias?
‘Rename’ is a permanent name given to a table or column
‘Alias’ is a temporary name given to a table or column.
33. What is a Join?
Join is a query, which retrieves related columns or rows from multiple tables.
34. What are the different types of joins?
Types of Joins are as follows:
35. What is the difference between an inner and outer join?
An inner join returns rows when there is at least some matching data between two (or more) tables that are being compared.
An outer join returns rows from both tables that include the records that are unmatched from one or both the tables.
36. What are SQL constraints?
SQL constraints are the set of rules that enforced some restriction while inserting, deleting or updating of data in the databases.
37. What are the constraints available in SQL?
Some of the constraints in SQL are – Primary Key, Foreign Key, Unique Key, SQL Not Null, Default, Check and Index constraint.
38. What is a Unique constraint?
A unique constraint is used to ensure that there are no duplication values in the field/column.
39. What is a Primary Key?
A PRIMARY KEY constraint uniquely identifies each record in a database table. All columns participating in a primary key constraint must not contain NULL values.
40. Can a table contain multiple PRIMARY KEY’s?
The short answer is no, a table is not allowed to contain multiple primary keys but it allows to have one composite primary key consisting of two or more columns.
41. What is a Composite PRIMARY KEY?
Composite PRIMARY KEY is a primary key created on more than one column (combination of multiple fields) in a table.
42. What is a FOREIGN KEY?
A FOREIGN KEY is a key used to link two tables together. A FOREIGN KEY in a table is linked with the PRIMARY KEY of another table.
43. Can a table contain multiple FOREIGN KEY’s?
A table can have many FOREIGN KEY’s.
44. What is the difference between UNIQUE and PRIMARY KEY constraints?
There should be only one PRIMARY KEY in a table whereas there can be any number of UNIQUE Keys.
PRIMARY KEY doesn’t allow NULL values whereas Unique key allows NULL values.
45. What is a NULL value?
A field with a NULL value is a field with no value. A NULL value is different from a zero value or a field that contains spaces. A field with a NULL value is one that has been left blank during record creation. Assume, there is a field in a table is optional and it is possible to insert a record without adding a value to the optional field then the field will be saved with a NULL value.
46. What is the difference between NULL value, Zero, and Blank space?
As I mentioned earlier, Null value is field with no value which is different from zero value and blank space.
Null value is a field with no value.
Zero is a number
Blank space is the value we provide. The ASCII value of space is CHAR(32).
47. How to Test for NULL Values?
A field with a NULL value is a field with no value. NULL value cannot be compared with other NULL values. Hence, It is not possible to test for NULL values with comparison operators, such as =, <, or <>. For this, we have to use the IS NULL and IS NOTNULL operators.
62. Define the SELECT INTO statement.
The SELECT INTO statement copies data from one table into a new table. The new table will be created with the column-names and types as defined in the old table. You can create new column names using the AS clause.
2 | SELECT RIGHT(EmpName,5)ASEmployeeName FROM Employee SELECT SUBSTRING(EmpName,1,5)ASEmployeeName FROM Employee |
78. How to add new Employee details in an Employee_Details table with the following details
Employee_Name: John, Salary: 5500, Age: 29?
UPDATE Employee_Details set Salary=7500where Employee_Name=‘John’; |
81. Write an SQL Query to select all records from the table?
82. How To Get List of All Tables From A DataBase?
To view the tables available on a particular DataBase
2 4 | GO GO |
83. Define SQL Delete statement.
The SQL Delete statement is used to delete records from a table.
SELECT *FROM Employee_Details WHERE Employee_Name like'E%'; |
Output:
2 | sp_rename'TableName.OldColumnName','NewColumnName' |
94. How to select all the even number records from a table?
To select all the even number records from a table:
2 |
95. How to select all the odd number records from a table?
To select all the odd number records from a table:
96. What is the SQL CASE statement?
SQL Case statement allows embedding an if-else like clause in the SELECT statement.
97. Can you display the result from the below table TestTable based on the criteria M,m as M and F, f as F and Null as N and g, k, I as U
2 4 6 8 | case when Gender='g'then'U' when Gender='NULL'then'N' endasnewgender from TestTable GROUP BY Gender |
98. What will be the result of the query below?
select casewhen null=nullthen'True'else'False'endasResult; |
This query returns “False”. In the above question, we could see null = null is not the proper way to compare a null value. To compare a value with null, we use IS operator in SQL.
So the correct way is as follows
select casewhen nullisnullthen'True'else'False'endasResult; |
99. What will be the result of the query below?
select casewhen nullisnullthen'Queries In SQL Server'else'Queries In MySQL'endasResult; |
This query will returns “Queries In SQL Server”.
100. How do you update F as M and M as F from the below table TestTable?
UPDATE TestTable SET Gender=CASEGender WHEN'F'THEN'M'ELSE'F'END |
101. Describe SQL comments?
Single Line Comments: Single line comments start with two consecutive hyphens (–) and ended by the end of the line
Multi-Line Comments: Multi-line comments start with /* and end with */. Any text between /* and */ will be ignored.
102. What is the difference between NVL function, IFNULL function, and ISNULL function?
These three functions work in the same way. These functions are used to replace NULL value with another value. Oracle developers use NVL function, MySQL developers use IFNULL function and SQL Server developers use ISNULL function.
Assume, some of the values in a column are NULL.
If you run below statement, you will get result as NULL
Suppose any of the value in col3 is NULL then as I said your result will be NULL.
To overcome this we use NVL() function, IFNULL() function, ISNULL() Function. Call of duty play online no download.
ORACLE:
MySQL:
Also, you can use the COALESCE() function