SQL
Structured Query Language
Shortcut to execute a query
F5
SQL statement used to extract data from a database
SELECT
SQL Statement used to update data in database
UPDATE
SQL Statement used to delete data in database.
DELETE
RDMS
Relational Database Management System
It is where the databases, tables, view stored procedures, users, etc are listed.
Object Explorer
How to select a column named "customerId" from a table named "Customers"?
SELECT customerId FROM Customers
How to select all the columns from a table named "Customers"?
SELECT * FROM Customers
How to select all unique values from all the columns of a table named "Customers"?
SELECT DISTINCT * FROM Customers
DBMS
Database Management System
It is where we can build and execute our queries.
Query Editor
Write an SQL query to fetch “FIRST_NAME” from Worker table using the alias name as <WORKER_NAME>.
SEELCT FIRST_NAME AS WORKER_NAME FROM Worker
Write an SQL query to print all Worker details from the Worker table order by FIRST_NAME Ascending.
SELECT * FROM Worker ORDER BY FIRST_NAME
Write an SQL query to print details for Workers with the first name as “Vipul” and “Satish” from Worker table.
SELECT * FROM Worker WHERE FIRST_NAME IN ('Vipul','Satish');
SSMS
SQL Server Management Studio
You can create multiple databases.
TRUE
Write an SQL query to print details of the Workers whose FIRST_NAME contains ‘a’.
SELECT * FROM Worker WHERE FIRST_NAME LIKE '%a%';
Write an SQL query to print details of the Workers whose SALARY lies between 100000 and 500000.
SELECT * FROM Worker WHERE SALARY BETWEEN 100000 AND 500000
Numeric values need Single quotation marks (')
FALSE
ANSI
American National Standards Institute
How to connect to a database when running a query?
1. Select from dropdown.
2. USE <database? GO
Write an SQL query to show the top n (say 10) records of a table named Worker sorted by salary.
SELECT TOP 10 * FROM Worker ORDER BY Salary DESC
Write an SQL query to clone a new table from another table.
SELECT * INTO newTable FROM oldTable
SQL Statement that deletes all the data from a table but not the table itself
TRUNCATE