1.

Important SQL Keywords

Answer»

The below table lists some important keywords used in SQL, along with their description and example.

KeywordDescriptionExample
ADDWill add a new column to an existing table.ALTER TABLE student ADD email_address VARCHAR(255)
ALTER TABLEAdds edits or deletes columns in a tableALTER TABLE student DROP COLUMN email_address;
ALTER COLUMNCan change the datatype of a table’s columnALTER TABLE student ALTER COLUMN phone VARCHAR(15)
ASRenames a table/column with an alias existing only for the query duration.SELECT name AS student_name, phone FROM student;
ASCUsed in conjunction with ORDER BY to sort data in ascending order.SELECT column1, column2, … FROM table_name ORDER BY column1, column2, … ASC;
DESCUsed in conjunction with ORDER BY to sort data in descending order.SELECT column1, column2, … FROM table_name ORDER BY column1, column2, … DESC;
CHECKConstrains the value which can be added to a column.CREATE TABLE student(fullName varchar(255), age INT, CHECK(age >= 18));
CREATE DATABASECreates a new database.CREATE DATABASE student;
DEFAULTSets the default value for a given column.CREATE TABLE products(ID int, name varchar(255) DEFAULT ‘Username’, from date DEFAULT GETDATE());
DELETEDelete values from a table.DELETE FROM users WHERE user_id= 674;
DROP COLUMNDeletes/Drops a column from a table.ALTER TABLE student DROP COLUMN name;
DROP DATABASECompletely deletes a database with all its content within.DROP DATABASE student;
DROP DEFAULTRemoves a default value for a column.ALTER TABLE student ALTER COLUMN age DROP DEFAULT;
DROP TABLEDeletes a table from a database.DROP TABLE students;
FROMDetermines which table to read or delete data from.SELECT * FROM students;
INUsed with WHERE clause for multiple OR conditionals.SELECT * FROM students WHERE name IN(‘Scaler’, ‘Interviewbit’,‘Academy’);
ORDER BYUsed to sort given data in Ascending or Descending order.SELECT * FROM student ORDER BY age ASC
SELECT DISTINCTWorks in the same war as SELECT, except that only unique values are included in the results.SELECT DISTINCT age from student;
TOPUsed in conjunction with SELECT to select a fixed number of records from a table.SELECT TOP 5 * FROM students;
VALUESUsed along with the INSERT INTO keyword to add new values to a table.INSERT INTO Customers (CustomerName, City, Country) VALUES (‘Cardinal’, ‘Stavanger’, ‘Norway’);
WHEREFilters given data based on some given condition.SELECT * FROM students WHERE age >= 18;
UNIQUEEnsures that all values in a column are different.UNIQUE (ID)
UNIONUsed to combine the result-set of two or more SELECT statements.SELECT column_name(s) FROM Table1 UNION SELECT column_name(s) FROM Table2;
UNION ALLCombines the result set of two or more SELECT statements(it allows duplicate values)SELECT City FROM table1 UNION ALL SELECT City FROM table2 ORDER BY City;
SELECT TOPUsed to specify the number of records to return.SELECT TOP 3 * FROM Students;
LIMITPuts a restriction on how many rows are returned from a query.SELECT * FROM table1 LIMIT 3;
UPDATEModifies the existing records in a table.UPDATE Customers SET ContactName = ‘Scaler’, City = ‘India’ WHERE CustomerID = 1;
SETUsed with UPDATE to specify which columns and values should be updated in a table.UPDATE Customers SET ContactName = ‘Scaler’, City= ‘India’ WHERE CustomerID = 1;
IS NULLColumn values are tested for NULL values using this operator.SELECT CustomerName, ContactName, Address FROM Customers WHERE Address IS NULL;
LIKEUsed to search for a specified pattern in a column.SELECT * FROM Students WHERE Name LIKE ‘a%’;
ROWNUMReturns a number indicating the order in which Oracle selects the row from a table or set of joined rows.SELECT * FROM Employees WHERE ROWNUM < 10;
GROUP BYGroups rows that have the same values into summary rows.SELECT COUNT(StudentID), State FROM Students GROUP BY State;
HAVINGEnables the user to specify conditions that filter which group results appear in the results.HAVING COUNT(CustomerID) > 5;



Discussion

No Comment Found