SQL-LEARNING DIARY2

1.NULL Value

A NULL value is different from a zero value or a field that contains spaces. A field with a NULL value is one that has been left blank during record creation!

1.Syntax

  • S NULL Syntax
SELECT column_names
FROM table_name
WHERE column_name IS NULL;
  • IS NOT NULL Syntax
SELECT column_names
FROM table_name
WHERE column_name IS NOT NULL;

3.Operator

  • The IS NULL Operator
    test for empty values (NULL values)

  • The IS NOT NULL Operator
    test for non-empty values (NOT NULL values)

2.UPDATE Statement

modify the existing records in a table.
1.UPDATE Syntax

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

EXAMPLE : updates the first customer (CustomerID = 1) with a new contact person and a new city.

UPDATE Customers
SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
WHERE CustomerID = 1;

2.UPDATE Multiple Records

  • It is the WHERE clause that determines how many records will be updated.
    method1:
UPDATE Customers
SET ContactName='Juan'
WHERE Country='Mexico';

%%update the contactname to “Juan” for all records where country is “Mexico”

method2:

UPDATE Customers
SET ContactName='Juan', Country='Mexico';

3.Update Warning!
If you omit the WHERE clause, ALL records will be updated!

3.delete

delete existing records in a table.

DELETE FROM table_name WHERE condition;

4.SELECT TOP Clause

specify the number of records to return and useful on large tables with thousands of records.
method1:
SQL statement selects the first three records from the “Customers” table:

SELECT TOP 3 * FROM Customers;

method2: LIMIT clause

SELECT * FROM Customers
LIMIT 3;

method2: ROWNUM

SELECT * FROM Customers
WHERE ROWNUM <= 3;

5.MIN() and MAX() Functions

  1. MIN() Syntax
    The MIN() function returns the smallest value of the selected column.
SELECT MIN(column_name)
FROM table_name
WHERE condition;
  1. MAX() Syntax
    The MAX() function returns the largest value of the selected column.
SELECT MAX(column_name)
FROM table_name
WHERE condition;

6.COUNT(), AVG() and SUM() Functions

  1. COUNT() Syntax
    The COUNT() function returns the number of rows that matches a specified criteria.
SELECT COUNT(column_name)
FROM table_name
WHERE condition;
  1. AVG() Syntax
    The AVG() function returns the average value of a numeric column.
SELECT AVG(column_name)
FROM table_name
WHERE condition;
  1. SUM() Syntax
    The SUM() function returns the total sum of a numeric column.
SELECT SUM(column_name)
FROM table_name
WHERE condition;

REFERENCE:https://www.w3schools.com/sql/default.asp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值