sql
sql
quantity_sold ) as
Remaining
-----------------------------------------------------------------------------------------------------------------
FROM tbl_Sales t1
WHERE t1.quantity_sold = 0;
--------------------------------------------------------------------------------------------------------------
--------------function----------------------------------------------------------------------------------------
@Quantity INT
)
RETURNS DECIMAL(10, 2)
AS BEGIN
RETURN @TotalPrice;
END;
---------------------------------------------------------------------------------------------------------------
---------trigger----------------------------------
on tbl_Products
for
insert,update ,delete
as
print 'you can not insert,update and delete this table i'
rollback;
------------------index-------------------------------------------------
ON tbl_Products (product_name);
----------------------------------------------------------------------------------------------------------------
------store procedure----------------
@UserName varchar(50)
As
Begin
End
@product_id Int,
@product_name varchar(500),
@stock_quantity Int
As
Begin
Begin
End
Else
Begin
Select 'Invalid Prod ID' As Output
End
End
--------------------------trigger--------------------
after insert
as
begin
values (@product_id,@product_name,@stock_quantity)
end
go
Tables: Insert, Delete, update, truncate, drop, select
TABLES
SELECT
SELECT * FROM Table_Name;
Count Distinct
SELECT COUNT(DISTINCT Column_Name) FROM Table_Name;
From table_name
Where condition;
Operators
ORDER BY: sort the result set
Syntax: SELECT Column1, Column2, …
From table_name
AND Operator
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;
AND vs OR
The AND operator displays a record if all the conditions are TRUE.
OR Operator
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;
NOT Operator
SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;
NOT LIKE
SELECT * FROM Customers
WHERE CustomerName NOT LIKE 'A%';
NOT BETWEEN
SELECT * FROM Customers
WHERE CustomerID NOT BETWEEN 10 AND 60;
NOT IN
SELECT * FROM Customers
WHERE City NOT IN ('Paris', 'London');
INSERT INTO
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);