Pandas and SQL Flashcards
<p>What happens if execute the following code?</p>
<p>Create newTable(col1 INT, col2 CHAR(25));</p>
<p>It will raise me error because you forgot to mention the keyword table .</p>
<p>Correct Syntax</p>
<p>Create table newTable(col1 INT, col2 CHAR(25);</p>
<p>What is the difference between unqiue Key and primary key?</p>
<p>There may be many unique key columns in a table but there can be only ONE primary key column.</p>
<p>What happens when I assign a certain column as Unique key?</p>
<p>It makes sure that all the entries in that column are unique and has no duplicates</p>
<p>Create a table with 1)Auto increment 2)uinique primary key 3)char , int and date-time columns .</p>
<p>CREATE TABLE Worker ( WORKER_ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT, FIRST_NAME CHAR(25), LAST_NAME CHAR(25), SALARY INT(15), JOINING_DATE DATETIME, DEPARTMENT CHAR(25) );</p>
<p>What happens if I try to execute the following code?</p>
<p>CREATE TABLE NewTable(S.No INT PRIMARY KEY);</p>
<p>It will raise and error because '.' is not allowed for COLUMN name assingment. '_' Is allowed.So the appropriate word would be 'S_No'</p>
<p>Insert values into table that has columns 'Column1'(INT) and 'Column2'(string)</p>
<p>INSERT INTO Table_Name (Column1, Column2) VALUES (001, 'Monika')</p>
<p>What happens if I execute this ?</p>
<p>INSERT INTO TABLE newtable3(col1,col2,col3) VALUES (1,2,'Hello');</p>
<p>This will raise me an error because we DONT HAVE to specify keyword table in this case .</p>
<p>Correct Syntax:</p>
<p>INSERT INTO newtable3(col1,col2,col3) VALUES (1,2,'Hello');</p>
<p>What is the differnce between create and Insert in terms of syntax?</p>
<p>In case of Create we will have to mention the keyword TABLE</p>
<p>But in case of Insert we SHOULDNT mention the keyword , or else it will give me syntax error</p>
<p>Get all unique elements from duplicates in certain column of sql table</p>
<p>SELECT DISTINCT column1, column2, ...FROM table_name;</p>
<p>Get all elements form a certain column in SQL table</p>
<p>Select column_name from table_name</p>
<p>Get elements from certain column while specifying criteria SQL</p>
<p>SELECT column1, column2, ... FROM table_name WHERE column1>thresh_val;</p>
<p>Get elements that DO NOT satisfy specific condition in said column</p>
<p>SELECT column1, column2, ...FROM table_nameWHERE NOT colum1="Sunny";</p>
<p>Get elements with multiple condtions are applied at the same time</p>
<p>SELECT * FROM Customers WHERE Country='Germany' AND City='Berlin';</p>
<p>Get elments that is union of completely different search filters</p>
<p>SELECT * FROM CustomersWHERE Country='Germany' OR Country='Spain';</p>
<p>Get elements in Ascending order</p>
<p>SELECT * FROM CustomersORDER BY Country ASC;</p>
<p>Get elements in Descedning order</p>
<p>SELECT * FROM CustomersORDER BY Country DESC;</p>
<p>Update specific records of a table based on search conditions</p>
<p>UPDATE Customers SET ContactName = 'Alfred Schmidt', City= 'Frankfurt' WHERE CustomerID = 1;</p>
<p>What happens if I do this?UPDATE CustomersSET ContactName='Juan';</p>
<p>All entries will get updated regradless of any country , age , City etc. It is essential that while updating the correct filters are applied .Or it will corrupt entire data.</p>
<p>What happens if we execute the following code?</p>
<p>UPDATE Customers SET ContactName = 'Amos' AND Country = 'India' WHERE CustomerID = 1;</p>
<p>I will raise me an error , because for set compnonet we shouldnt use AND, instead we should use comma</p>
<p>UPDATE Customers SET ContactName = 'Amos',Country='India' WHERE CustomerID = 1;</p>
<p>How to delete specific elements in table?</p>
<p>DELETE FROM table_name WHERE Name = "Sunny";</p>
<p>What is one important warning to remember while deleting entries in SQL ?</p>
<p>We should careful regarding the condition we set in DELETE query DELETE FROM table_name WHERE condition;If we are not mindful of the condition then we might end up deleting the wrong entries.</p>
<p>How to delete all records from a certain table?</p>
<p>DELETE FROM table_name;</p>
<p>What happens if we execute the follwing line?DELETE Age from Table where Name='Sunny';</p>
<p>It will raise me a syntax error .Because we cant delete a specific column from table . Deletion removes the complete entry ,not just a column.</p>
<p>How to update all entries in Table?</p>
<p>UPDATE CustomersSET ContactName = 'Alfred Schmidt';</p>
<p>What happens if I exectue the following line?Update Student_Table where Name= "Sunny"</p>
<p>It will raise me an error because we havent specified the "set" component in update.</p>
<p>What are important components of update statement?</p>
<p>Udate table , SET values and condition</p>
<p>What are important components of delete statement?</p>
<p>delete table and condition</p>
<p>What happens if I excute the following code?</p>
<p>CREATE TABLE NewTable(Column INT AUTO_INCREMENT PRIMARY KEY);</p>
<p>It wont raise an error . The order of AUTO_INCREMENT and the key assignment doesent matter</p>
<p>What happens if I execute the following line?Update Student_Table set Age = 20 where "Name" = Sunny</p>
<p>It will raise me an error because the field should not be a string and the value its checking (Sunny) should be a string.</p>
<p>How to get top 10 elements of a table</p>
<p>SELECT S.No,NameFROM StudentLIMIT 10;</p>
<p>How to get bottom 10 element</p>
<p>SELECT S.No,NameFROM Student ORDER by S.No DESCLIMIT 10;</p>
<p>What type of statistical attributes can we calculate from numerical fields in data table?</p>
<p>We can calclulate , COUNT , MIN , MAX, SUM AND AVG</p>
<p>Format to calculate the statistical attributes of a table</p>
<p>Select MIN(Age) from Students where City = "Frankfurt"We can use the same for COUNT , MAX, SUM or AVG</p>
<p>Get Elements where the name starts with letter 'a'</p>
<p>SELECT * FROM CustomersWHERE CustomerName LIKE 'a%';</p>
<p>What key word should i use in case I want to find words that follow a certain pattern?</p>
<p>We should use the key words "LIKE"</p>
<p>Get elements that end with letter 'a'</p>
<p>SELECT * FROM CustomersWHERE CustomerName LIKE '%a';</p>
<p>What happens if I use the following syntax?SELECT * FROM CustomersWHERE CustomerName LIKE '*a';</p>
<p>This will raise me and error if I am using mySQL . But that wont be the case if we are using MS Access</p>
<p>Get elements where the middle word is "or"</p>
<p>SELECT * FROM CustomersWHERE CustomerName LIKE '%or%';</p>
<p>Get element that has second word 'r'</p>
<p>SELECT * FROM CustomersWHERE CustomerName LIKE '_r%';</p>
<p>Get elements that has starting letter 'a' and has atleast 3 words in the string</p>
<p>SELECT * FROM CustomersWHERE CustomerName LIKE 'a\_\_%'; Note: There are 2 '_' in the syntax above</p>