SQL Interview Questions
SQL Interview Questions
The semicolon (;) is used in SQL code as a statement terminator. For most SQL Server T-SQL statements it is not mandatory
2.Difference between JOIN and UNION
A JOIN is a means for combining fields from two tables by using values common to each. The SQL UNION operator combines the result of two or more SELECT statements.
3. Difference between order by and group by.
Group by statement is used to group the rows that have the same value. Whereas Order by statement sort the result-set either in ascending or in descending order.
4. SELECT Person.Name, COUNT(Sales.SalesID) AS NumberOfSales FROM Sales INNER JOIN Person ON Sales.Person.ID=Person.PersonID WHERE Name="Ram" GROUP BY Name HAVINGCOUNT(Sales SalesID) >15;
5. Is SQL case sensitive
SQL Server is, by default case insensitive;
6. What does drop function does.
The DROP FUNCTION statement is used to drop a stored function or a user-defined function (UDF)
7. What does truncate function does
The SQL TRUNCATE TABLE command is used to delete complete data from an existing table.
But not delete structure of table
8. What is a candidate key?
Candidate key is a single key or a group of multiple keys that uniquely identify rows in a table
9 When can you compare the dates in SQL
In SQL, the date value has DATE datatype which accepts date in 'yyyy-mm-dd' format. To compare two dates, we will declare two dates and compare them using the IF-ELSE statement.
10. What is the view? Explain with syntax
A view contains rows and columns, just like a real table
11. A view can be updated with which command
SQL UPDATE VIEW command can be used to modify the data of a view.
12. What is SQL injection:
SQL injection is a code injection technique that might destroy your database. SQL injection is one of the most common web hacking techniques.
13. When does SQL injection occurs
SQL injection attacks occur when a web application does not validate values received from a web form, cookie, input parameter, etc., before passing them to SQL queries that will be executed on a database server
14. What is batch of SQL statement
A batch of SQL statements is a group of two or more SQL statements or a single SQL statement that has the same effect as a group of two or more SQL statements
15. What is ENUM
An ENUM is a string object with a value chosen from a list of permitted values that are enumerated explicitly in the column specification at table creation time.
16. What are the types of SQL commands
There are 3 main types of commands. DDL (Data Definition Language) commands, DML (Data Manipulation Language) commands, and DCL (Data Control Language) commands.
17. What is the difference between Data definition language and Data manipulation language.
Data Definition Language is used to define the schema of a database. It deals with how the data gets stored in the database. Data Manipulation Language is used to manipulate i.e. retrieve, update and delete the data in a database. The DDL commands that are used in SQL are CREATE, DROP, ALTER, TRUNCATE, etc.
18. What is a Data query language.
Data Query Languages, are computer languages that are used to make various queries in information systems and databases
19. What is a Data control language?
Data Control Language (or DCL) consists of statements that control security and concurrent access to table data.
20. What is Transaction control language
Transaction Control Language commands are used to manage transactions in the database.
21. What is a subquery. Explain with syntax.
A subquery can be placed in a number of SQL clauses like WHERE clause, FROM clause, HAVING clause. You can use Subquery with SELECT, UPDATE, INSERT, DELETE statements along with the operators like =, <, >, >=, <=, IN, BETWEEN, etc. A subquery is a query within another query.
22. What are the types of views
There are three types of System defined views, Information Schema, Catalog View, and Dynamic Management View.
23. What is the difference between CONCAT and CONCAT_WS function.
Both CONCAT() and CONCAT_WS() functions are used to concatenate two or more strings but the basic difference between them is that CONCAT_WS() function can do the concatenation along with a separator between strings, whereas in CONCAT() function there is no concept of the separator.
24. What is the difference between ATAN and ATAN2function
The atan() function returns a value in the range -π/2 to π/2 radians. The atan2() function returns a value in the range -π to π radians
25. What is the difference between CEIL, FLOOR and ROUND function?
Ceil() takes the number and rounds it to the nearest integer above its current value, whereas floor() rounds it to the nearest integer below its current value.
26. What is a RAND() function
This function in SQL Server is used to return a random decimal value and this value lies in the range greater than and equal to zero (>=0) and less than 1.
27. What is the difference between LOCALTIMESTAMP and CURRENT_TIMESTAMP
difference between this function and CURRENT_TIMESTAMP is that
LOCALTIMESTAMP returns a TIMESTAMP value while
CURRENT_TIMESTAMP returns a TIMESTAMP WITH TIME ZONE value
28. Which function is used to create date and time.
GetDate() Date and Time
GETUTCDATE()
SYSDATETIME()
SYSUTCDATETIME() Current Date and. Time of the system
SYSDATETIMEOFFSET()
29. Name three functions that specify current date and time.
GETDATE(), SYSDATETIME(), and CURRENT_TIMESTAMP.
30. Which function returns the difference between two periods. And the result will be in which format.
DATEDIF() is a basic SQL Server function that can be used to do date math. Specifically, it gets the difference between 2 dates with the results returned in date units specified as years, months days, minutes, seconds as an int (integer) value
Comments
Post a Comment
If you have any doubts, please let me know