You are on page 1of 7
ri772024 ‘Basie SQL Interview Questions And Answers Pat ~ e-learning portal Basic SQL Interview Questions And Answers Pdf Insaction are known as ACID propetis, such as -Alomicity Ensures the completeness o al ransactons performed, Checks whether every transaction is completed successtulyif not than transactions aborted at the failure point and the previous transaction is rolled back t its inital state ‘8 changes undone Consistency: Ensures that all changos made through suecesslul transaction are rellacted properly on database Isolation: Eneures that ll ransactions ore performed independently and changes made by one transaction are not elected DDurabity: Ensures that the changes made in the database with committed transactions persist as itis even after a system tour. 2.b—plain sal Data types? [Anewer:in 8 Server, each column in a database table has a name and « data type. We need to decide what type of date to store inside each anc every column of a table while creating @ SQL table. 3. boplain the working of SQL Privileges? "Answer: SQL GRANT and REVOKE commands aro used to Implernont privlogos in SQL multiple user envronmonts. The ‘acministrator ofthe database ean grant or revoke privileges to of from users of database object Ike SELECT, INSERT, UPDATE, DELETE, ALL et. [GRANT Commanet This command is used to provide database access to user apart ftom an administrator ‘Syntax GRANT prvilog on object_name To {user_namelPuaLctrole_name} In the above syntax WITH GRANT, OPTIONS indicates thot the user can grant access to another user too, REVOKE commend: This command is uted to provide database deny oF remove access to database objects ‘Syntax: REVOKE privleg onobject_name FROM {usor_nome|PUBLIC|ole_narno}; 4. difference between TRUNCATE, DELETE and DROP commands? TRUNCATE removes ALL rows trom ot ble by de-allocating the memory pages. The operation cannot be rolled back ROP commans removes @ table ftom the database completely. 5. Whats Referential integrity? Answer: Sot of rules that restrict the values of one or more columns ofthe tables based on the values of the primary key oF Unique key ofthe referenced table. 6. What Ie the main difference between BETWEEN’ and! ‘IN’ condition operat Answer: BETWEEN operator is used to dsplaying rows based on a range of values ino row whereas the IN condition operator ‘sed to check for values contained in a spactfic set of values. Example of BETWEEN: SELECT * FROM Students where ROLL_NO BETWEEN 10 AND 50; Example of he SELECT * FROM students where ROLL_NOIN (8,528); 7.Why are sal functions used? “Answer: SQL functions are used forthe folowing purposes: ‘a perform some calculations on the data To modtyincvdual data To manipulate tre output To format dates ond numbers To conver the data types hitpssiswtechnologies.com/top-50-basicsqlinterview-questions-and-answers- pa! 19 ri772024 ‘Basie SQL Interview Questions And Answers Pat ~ e-learning portal £8. What do you mean by recursive stored p “Anewor: Recursive stored procedure refers to stored procedure which cals by itself unit reaches sore boundory ‘conaition. rhs recursive function or procedure helps the programmes to use the same set of coe n number of mes 9. What the dliference between HAVING’ CLAUSE onda‘WHERE’ CLAUSE? Answer: HAVING clause can be used only with SELECT staternent fis usualy Usain @ GROUP BY clause andl whenever (GROUP BY is not used HAVING behaves ike a WHERE clause. Having Clause is only used with the GROUP BY function ina query whereas WHERE Clause is applied ‘rea part ofthe GROUP BY function in query. ‘each row betore they 10, Uist come cas manipulation funetionsin sal? ‘There are three case manipulation functions in SQl, namely: LOWER: thie funetion returns the tring in lowercase. It takes © etting as an argument and returns by converting itinto lower cease, Syntax LoweR( sting) UPPER: This function retuins the string in uppercase takes a sting o& an argument and reluins it by converting into ‘uppercase. Syntax LUPPeRsting) INTCA®: This funtion returns the string with the first eter in uppercase and the rest of the leter in lowercase, Syntax: InTea@(string) _Apare from ths SQL Interview Questions blog you want to get tained ftom professionals on this technology, you can opt for Ce structured training rom SVR! Click below to know more, 11.Whatis an AUAS command? [Anawer: ALIAS name can be given to any table or @ column, This alias name can be referred in WHERE clause te klentity@ portieular table or a column For example~ Select empempld, deptResut rom employee emp, department os dept where empempiD=deptempio In the above example, emp roles to alas name for employee table and dept relers to alias name for department table 12. What are the aggregate and seal “Anewer: Aggregate functlons are used to evaluate mathematica calculation and retum a single value, These calculations functions? 6ore done trom the columns in a table. For example- max(),count() are calculated with respect to numeric Sealar functions retuin single value based on the input value. For example ~ UCASE(), NOW() is ealeulatad with respect toa sting 1. Whatisa Stored Procedure? Answer: A Slored Procedure i fun tion which consists of many SOI statements to access the database system. Several SQL statements are consolidated into stored procedure and execute them whenever and wherever requited which saves time and avoid wring code again andl again, 14. Uist some advantages and disadvantages of stored Procedure? Advantages A Stored Procedure can be used ae modular programming which means create once, store and cal for sever Uhenever itis required. Thie supports faster execution also reduces network trate and provides better security tothe data, olsadvantage: ‘The only disadvantage of Stored Procedure is that it ean be executed only in the database and utiles more memory inthe ctabate sever. 15, Ustollthe types of user-defined functions? Anewor: + Scolar Functions hitpssiswtechnologies.com/top-50-basicsqlinterview-questions-and-answers- pa! 29 ri772024 ‘Basie SQL Interview Questions And Answers Pat ~ e-learning portal + Inline Toble-valued tunetions 16, what do you mean by Coll Answer: Collation |s defined os a st of rules that determine how data can be sorted as well as compared. Character datas one sorted using the rulos that define the coract character sequence along with options for speclying caso-sonsivly, ‘character wiath et. what ar the atferent types of Coll tion Sensitivity? Answer: Following are the ditferent types of collation sensitivity: cote Sensitivity: Acne and Band, ana Sensitivity: Japanese Kana characters. ‘Width sonsitivit Accent Sensitivity ingle byte character and double-byte character. [Apart from this SQ{ Interview Questions Blog, if you want to get trained from professionals on this technology, you ean opt for structured training rorn SVR 3 meds In SQL Server? How can it be changed? [Anewer: Windows mode and Mixed Mode ~ SQL.and Windows. You can goto the below steps to change authentication mode in Sal Server: Click Stor Programs» Microsoft SQl Sewer and click SQ\ Enterprise Manager to un SOI Enterprise Manager ftom the Microsoft S91 Server program group. ‘Thon select the server fom the Tools menus Seloct SQL Server Configuration Propertoe, and choose the Security page. 3. Whats @ Data warehouse? Anewer: Datawarehouse refers to @ central repository of data where t information. Those data ate consolidated, transformed and made availabe fr the mining a8 well as aniline processing, Worohouse data alse have a subset af date called Date Marts ‘data is assembled ram multiple sources of 20, Whatare Local and Global variables? Local variables ‘Those vorisbles con be used oF sist only inside the function. Thase variable are not used or refered by any other function ot ‘hese variables are the variables which can be accessed throughout the pragiam. Global variables cannot be created whenever that function is called varia 21. How can yeutetch alternate records from a table? [Anewer: You can fetch alternate records |e both odd and even row numer. For example To alsplay even numbers use the following commane: ‘select stunt from (Select row, students fom student) wher Now, to display odd numbers: Select stucent from (Select row, student trom student) where mod(row2)=1 modrow2)= 22, when: re we going toure truncate and delete? \We cant execute a tigger in cose of TRUNCATE whilst with DELETE, we can accomplish o tigger TRUNCATE le quicker than DELETE, fr the reason that when we use OE stotistes inthe rollback gop on or after where we can get the data back attr removal. the case of TRUNCATE. it wll not store data in rllpack gap and will unewarvingly ub It out. TRUNCATE do not recover the deleted dota, Eto delete the data, o mei teres the whole hitpssiswtechnologies.com/top-50-basicsqlinterview-questions-and-answers- pa! a9 ri772024 ‘Basie SQL Interview Questions And Answers Pat ~ e-learning portal ‘We can uso any conettion in WHERE clause using DELETE but itis not possible with TRUNCATESII a table i releronced by any foreign key constraints, then TRUNCATE wor't work {Go through this SQL tutorial to leain more about SQ. commands 23. Whatis the SQL CASE statement u for? Explain with an example? IRailows you to embed an if-else tke @ clause in the SELECT clause, ‘SELECT Employee _Nome, CASE Location WHEN ‘Alex THEN Bonus *2 exo FROM Intalipaat employee Read this blog to lear why SOL Optimization has always been an important aspect of database management 24, How do youmaintain database integrity where deletions from one table will automatically cause deletions in another table? ‘You can ereote a trigger that wil automatically delete elements in the second table when elements trom te frst table ore 25. Howton the second highest salary of an Employee? “Anewor: There are many ways to find the second highest salary of employees in $0. You con either use SQL Join oF Subquery to solve this problern. loro fs SQL quory using Subquery Soloct MAx(Salay) trom Intolipaat _emplyee WHERE Salary NOTIN (solact MAX. “Anewor:f tre developer needs to perform the row by row operations for the result set containing more than one row, then he unambiguously declares « pointer with a name, They are managed by OPEN, FETCH and CLOSE XFOUND, XNOFOUND, %ROWCOUNT, and %ISOPEN characteristics are used in all ypes of pointers 27. Explain correlated query work? "Anawer: I's most important to be attentive tothe arrange of operations in an interrelated subquery Fist, a row is processed in the outer doubt ‘Then for that exacting row, the subquery is executed ~ as aresut for each row processed by the outer quot, the subquery Wil aso be processed. In « correlated subquery, each time a line is worked for Empl, the subquery wl also make a decision ‘nthe exacting rows value for Empl, Salary and run. And the outer query will move on tothe next row, and the subquery wi ‘execute for that rows value of Empl Salary ew persist in anticipation of tne “WHERE (I) = (.)* state is pleased, 28, When isthe UPOATE_STATISTICS command used? “Anewer: This command is used, ons the processing of large data is done, \Wnon wo dolete a large number oes, alteration or reproduction takes plac inthe changes we need bles, to be concerned about these restructure the indexes This is done UPDATE STAIISICS. 25. whatiea Subquery? Answer: A Subquery i a SQL query within another query. ie a subset ofa Select st ‘tering the concitions ofthe main query ose return values are used in n wile insertion, deletion or updation of dat in the [Anewer: SQ. constraints ate the sot of rules that impose some rest {databates. In SQL we have both column level ae well as tle evel constraints which are applied at columns and tables respectively. Some of constraints in 8 ate ~ Primary Koy Foreign Key, Unique Key, Not NULL, DEFAULT, CHECK an index hitpssiswtechnologies.com/top-50-basicsqlinterview-questions-and-answers- pa! 49 ri772024 ‘Basie SQL Interview Questions And Answers Pat ~ e-learning portal 431, What are the different DCL commands in SQL? [Anewor: DCL commands are used to create roles, grant permission and controlaccess tothe database objacts (GRANT: To provide user access DENY: To deny permissions to users REVOKE: 432, What ie a Primary Key? Answer: primary key 6 column oF @ combination of columns which uniquely identifies ¢ record inthe databose, A primary key can only have unique onc nat NULL values and there ean be only one primary key in a table. 32, How to add code tothe existing article (Using Improve Article)? -Anewer:Rocursive Practice Problems wlth Solutions un Levels in unas 24, Explain Boyce and Codd Norma Form(BCNF)? Answer: CHF isthe advanced or sticter version of INF. For each functional dependency X=» Y= X should be the super key 35. Explain the First Normal Form(INF)? “Anewer: Scoring to Fret Normal Form, @ column cannot have multiple values, each value inthe columns must be atomic. functions insqu? Answer: Scalar functions or 1 functions that return a single vale by processing « single value in SQL. Some ofthe widely sed SOL functions ar LUcASE() -USed to convert a sting to upper case LCASE() ~ Usod to corwort a stting to lower caso ROUND) ~ Used to round a number o the decimal places spectied Now() Used io feten curent astern date and time EN0 = Used to tina the length of string SUBSTRING) oF MDD) - MID and SUBSTRING ae synonyms in SQL. They are used specityng the start and end index Syntax -SUBSTRING(ColumnName.stantndexendlndoy). LOCATE) ~ Uses ta find the index ofthe character in as IM) ~ Used tim spaces trom et extract ou ing. Syntax~ LOCATE(character ColumaName) RTRIM() ~ Used to trim spaces from right a7. Whatieac [Anewer: Coclesce function used to return the fist, not NULL alu oUt of the multiple values or expressions pasted tothe coslesce function os porameters ample CCOALESCE(NULL, NULL, 5 "AtOFTesting’) will retum the value S. (COALESCE(NULI, NULL, NUL) wl return NULL value sno Not NULL value Is encounterodiin tho parameters ts 38, What are th ferent types of joine? ‘Types of Joins areas follows: + RIGHT JON + OUTER JON + View Complete Post 29, what you mean by Subquery? “Anewer: Query within another query is called as Subquery. subquery i called inner query which retums output that Ito be sed by another query hitpssiswtechnologies.com/top-50-basicsqlinterview-questions-and-answers- pa! ri772024 ‘Basie SQL Interview Questions And Answers Pat ~ e-learning portal 40, whats a Unique key? Answer: Unigualy identifies @ single row inthe table. $e values allowed per table -Aport from this SQL Interview Questions biog ou want to get tained ftom professionals. on this technology, ou can opt for structured training rom SvRt ‘41. What de you mean by data integrity? “Answer: Data integrity dofines accuracy as well asthe consistency ofthe data stored ina database. tls defines intogrity ‘constraints to anforee business rules on the data when fis entered into an application or @ database, 42, writea SQL query to display the current dat “Answer: In Sl, thoros a bul-in function called GetDate() which helps to return the current imestomp/ate. [Anewor:Databore Management system isa collection of programs that enables a user to store, retrieve, update ond delete Jn trom a databae. iHerent DDL command sal Answer: DOL commands are used to define or ater the structure ofthe database ‘CREATE: To create databases and datavase objects ALTER To attr existing database objocts DROP: To crop databases and databases objects “TRUNCATE: To remove al records rom @ table but not its database structure RENAME: To rename database objects 45, what ore Constraints? “Anewor: Constraints are used to specity the limit onthe data type ofthe t the table statement lo. Itcan be specified while creating or altering ‘The sample of constraint + Nor Nu + check + unaue + PRIMARY KEY + FOREIGN KEY 45, Explain itferont typos of index? ‘There are three types of index namely: Unique Index: This index dss not allow the fel to have duplicate values the column is unique indexed. Ifa primary key is defined, nique inex can be applied automaticaly ‘This index reorders physical order of the table ond searches based on the boss of key vahes, Each table con only have cone clustredingex Non-Clustered Index Non-Clustered Indox does not altr the physical order of the table and maintins a logical order othe data. Fach table con have many nonclustered indoxes. £47 Explain different types of Normalization? [Anewer: There are many successive levels of normalztion, Tese are called normal forms. Each consecutive normal form depends onthe previous one. hitpssiswtechnologies.com/top-50-basicsqlinterview-questions-and-answers- pa! ri772024 ‘Basie SQL Interview Questions And Answers Pat ~ e-learning portal ‘To fst threo normal forms are usualy adequate First Normal orm (INF) ~ No repeating groups within rows ‘Second Normal Form (24) ~ Every non-key (supporting) column value I dependent on the whole primary key. ‘Third Normal Form (BF) - Dependent solely an the primary key and no other non-key (supporting) columa value 48, whats ACID property in [Anewer: CID stonds for Atornicty, Consistency, oation, Ouradity Is used to ensure thatthe date transactions are latabase? processed roiably in a database system. [Atomicity: Atomic refers ta the transactions that are completely done of failed where transo: ‘operation ofa data, means Hone part of any transaction fal, hs ‘unchanged ion refers assingle logical sire transaction fails and the database state is lott consistency: Consistoncy ensures thatthe dota must meet al the validation rules. In simple words, ou can say that your ‘transaction never eaves the datobase without complatin ite stat, lation: The rain goal of soation is concurrency conto Durability: Curcilly means that if transaction has been committed, twill occur whatever may come in between such at ower loss, erash or any sort of error. 49. what, you meen by “Tigger” in SQL? _Anewer: Trigger in SQLs ate a special type of stored procedures that are defined to execute autornaticaly in place or after {dala modifications. allows you to execute a batch of code when an insert, update or any other query is executes against o spect table. 50, Whatare the aifforent operators availa insu? (Fe three operators availabe in SQ}, namely: Arithmetic Operators .ogical Operators Answer: Ihe ‘comparison oper ‘port from this SQL interview Questions blog you want o get tained ftom professionals on this technology, you can opt for ‘structured training trom svt Note: Browse latest SQL Interview Questions and SQL Tutorial Videos. Hee you can check SQL Training details and Sal ‘raining Videos for salt learning. Contact +01 988 902 2027 far mare information SQL Videos x arencad Free Bundle Videos Next version Access htpsiiswtechnologies.com/top-50-basicsqlinterview-questions-and-answers-pai! 79

You might also like