SQL SELECT TOP

The SELECT TOP statement is used to retrieve the top specified number of rows from a table. Syntax: SELECT TOP n * FROM tableName Where n is the number of rows. Example: SELECT TOP 2 * FROM EMPLOYEE;SELECT TOP 2 * FROM EMPLOYEE; Output: EMP_ID EMP_NAME AGE SALARY 1 Parbhjot 28 35000 5 Parmender 28 45000EMP_ID EMP_NAME AGE SALARY 1 … Read more

Categories SQL

SQL DISTINCT keyword

The DISTINCT keyword is used to retrieve the unique records by eliminating the all duplicate records. Syntax: SELECT DISTINCT column1, column2,…..columnN FROM tableName WHERE [condition] Example: SELECT DISTINCT EMP_NAME FROM EMPLOYEE;SELECT DISTINCT EMP_NAME FROM EMPLOYEE; Output: EMP_NAME Nidhi Parbhjot ParmenderEMP_NAME Nidhi Parbhjot Parmender   Next Topic: SQL SELECT TOP with example. Previous Topic: SQL UNIQUE … Read more

Categories SQL

SQL UNIQUE keyword

The UNIQUE keyword is used to retrieve the unique records by eliminating the all duplicate records. Syntax: SELECT UNIQUE column1, column2,…..columnN FROM tableName WHERE [condition] UNIQUE and DISTINCT statements are same and will give the same result sets. Example: SELECT UNIQUE EMP_NAME FROM EMPLOYEE;SELECT UNIQUE EMP_NAME FROM EMPLOYEE; Output: EMP_NAME Nidhi Parbhjot ParmenderEMP_NAME Nidhi Parbhjot … Read more

Categories SQL

SQL SELECT

The SELECT statement is used to retrieve the data from a database table in the form of result sets. Syntax of SELECT to fetch all columns: SELECT * FROM tableName; Example: SELECT * FROM EMPLOYEE;SELECT * FROM EMPLOYEE; Output: EMP_ID EMP_NAME AGE SALARY 1 Parbhjot 28 35000 5 Parmender 28 45000 2 Parmender 30 45000 … Read more

Categories SQL

SQL UPDATE statement

The UPDATE statement is used to modify the existing record in a table. Syntax: UPDATE tableName SET columnName1 = value1, columnName2 = value2,…, columnNameN = valueN WHERE [condition] Use where condition if you want to update a specific record otherwise all records will update. Example: UPDATE EMPLOYEE SET EMP_NAME = ‘Parmender’ WHERE EMP_ID = ‘5’;UPDATE … Read more

Categories SQL

SQL INDEX Constraint

The INDEX is used to create and retrieve data from the table very quickly. An INDEX is created with CREATE INDEX statement. Syntax: CREATE INDEX indexName ON tableName (column1, column2…..);  Drop an INDEX Constraint: Use the following syntax to drop an index constraint. ALTER TABLE tableName DROP INDEX indexName;   Next Topic: SQL INSERT statement … Read more

Categories SQL

SQL INSERT statement

The INSERT statement is used to insert a new record into the table. Ways to insert the data into a table: Inserting the data directly to a table. Inserting data to a table through a select statement. 1. Inserting the data directly to a table. In case when we insert the values in the specified … Read more

Categories SQL

SQL UNIQUE Constraint

The UNIQUE constraint is used to uniquely identify each row in a table. It is like primary key but it can contain one null value and a table can have more than one UNIQUE constraint. Syntax of UNIQUE Constraint on one column with CREATE TABLE statement: MySQL: CREATE TABLE Persons ( P_Id int NOT NULL, … Read more

Categories SQL

SQL NOT NULL Constraint

The NOT NULL constraint enforces a field or column to not contain a null value. Example of NOT NULL constraint with CREATE TABLE statement: CREATE TABLE PERSONS (   P_ ID INT NOT NULL,   NAME VARCHAR (20) NOT NULL,   AGE INT,   PRIMARY KEY (P_ID)   );CREATE TABLE PERSONS ( P_ ID INT NOT NULL, NAME VARCHAR (20) NOT … Read more

Categories SQL

SQL FOREIGN KEY

The FOREIGN KEY is used to define a relationship between two tables and a FOREIGN KEY in one table points to the PRIMARY KEY in another table. Syntax of FOREIGN KEY Constraint on one column with CREATE TABLE statement: MySQL: CREATE TABLE Orders ( Order_Id int NOT NULL, OrderNo int NOT NULL, P_Id int, PRIMARY … Read more

Categories SQL