SQL Workshop COPY Flashcards
What happens if execute the following code?
Create newTable(col1 INT, col2 CHAR(25));
It will raise me error because you forgot to mention the keyword table .
Correct Syntax
Create table newTable(col1 INT, col2 CHAR(25);
What is the difference between unqiue Key and primary key?
There may be many unique key columns in a table but there can be only ONE primary key column.
What happens when I assign a certain column as Unique key?
It makes sure that all the entries in that column are unique and has no duplicates
Create a table with 1)Auto increment 2)uinique primary key 3)char , int and date-time columns .
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) );
What happens if I try to execute the following code?
CREATE TABLE NewTable(S.No INT PRIMARY KEY);
It will raise and error because ‘.’ is not allowed for COLUMN name assingment. ‘_’ Is allowed.So the appropriate word would be ‘S_No’
Insert values into table that has columns ‘Column1’(INT) and ‘Column2’(string)
INSERT INTO Table_Name (Column1, Column2) VALUES (001, ‘Monika’)
What happens if I execute this ?
INSERT INTO TABLE newtable3(col1,col2,col3) VALUES (1,2,’Hello’);
This will raise me an error because we DONT HAVE to specify keyword table in this case .
Correct Syntax:
INSERT INTO newtable3(col1,col2,col3) VALUES (1,2,’Hello’);
What is the differnce between create and Insert in terms of syntax?
In case of Create we will have to mention the keyword TABLE
But in case of Insert we SHOULDNT mention the keyword , or else it will give me syntax error
Get all unique elements from duplicates in certain column of sql table
SELECT DISTINCT column1, column2, … FROM table_name;
Get all elements form a certain column in SQL table
Select column_name from table_name
Get elements from certain column while specifying criteria
SELECT column1, column2, … FROM table_name WHERE column1>thresh_val;
Get elements that DO NOT satisfy specific condition in said column
SELECT column1, column2, … FROM table_name WHERE NOT colum1=”Sunny”;
Get elements with multiple condtions are applied at the same time
SELECT * FROM Customers WHERE Country=’Germany’ AND City=’Berlin’;
Get elments that is union of completely different search filters
SELECT * FROM Customers WHERE Country=’Germany’ OR Country=’Spain’;
Get elements in Ascending order
SELECT * FROM Customers ORDER BY Country ASC;
Get elements in Descedning order
SELECT * FROM Customers ORDER BY Country DESC;
Update specific records of a table based on search conditions
UPDATE Customers SET ContactName = ‘Alfred Schmidt’, City= ‘Frankfurt’ WHERE CustomerID = 1;
What happens if I do this? UPDATE Customers SET ContactName=’Juan’;
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.
What happens if we execute the following code?
UPDATE Customers SET ContactName = ‘Amos’ AND Country = ‘India’ WHERE CustomerID = 1;
I will raise me an error , because for set compnonet we shouldnt use AND, instead we should use comma
UPDATE Customers SET ContactName = ‘Amos’,Country=’India’ WHERE CustomerID = 1;
How to delete specific elements in table?
DELETE FROM table_name WHERE Name = “Sunny”;
What is one important warning to remember while deleting entries in SQL ?
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.
How to delete all records from a certain table?
DELETE FROM table_name;
What happens if we execute the follwing line? DELETE Age from Table where Name=’Sunny’;
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.
How to update all entries in Table?
UPDATE Customers SET ContactName = ‘Alfred Schmidt’;
What happens if I exectue the following line? Update Student_Table where Name= “Sunny”
It will raise me an error because we havent specified the “set” component in update.
What are important components of update statement?
Udate table , SET values and condition