SQL Having

The HAVING was added to SQL because the WHERE keyword cannot be used with aggregate functions. Syntax:- SELECT column_name, aggregate_function(column_name) FROM table_name WHERE column_name operator value GROUP BY column_name HAVING aggregate_function(column_name) operator value; Example:- Now you want to find if any of the visitors has registered more than 10 orders. SELECT Visitors.LastName, COUNT(Orders.OrderID) AS NumberOfOrders FROM […]

SQL Alter Table

The SQL ALTER TABLE is used to add, delete or modify columns in an existing table. SQL Alter Table:- ALTER TABLE table_name ADD column_name datatype Drop Column:- ALTER TABLE table_name DROP COLUMN column_name; Add Unique Constraint:- ALTER TABLE table_name ADD CONSTRAINT MyUniqueConstraint UNIQUE(column1, column2…); Add Primary Key:- ALTER TABLE table_name ADD CONSTRAINT PrimaryKey PRIMARY KEY […]