Transact-SQL

DECLARE

DECLARE @gender varchar(30);   

DECLARE @find varchar(30) = 'Man%';

DECLARE @lastName varchar(30), @firstName varchar(30), @rows int;

DECLARE @age INT;

SET

SET @gender = 'Fema';

SET @gender += 'le';

SET @rows = (SELECT COUNT(*) FROM Customer);  

SET @age = 18;

SELECT

SELECT @gender = 'Man';

-- If CustomerID 1000 does not exists, @gender will retain its present value.
SELECT @gender = Gender FROM Customer WHERE CustomerID = 1000;

-- If CustomerID 1000 does not exists, @gender will be NULL
SELECT @gender = (SELECT Gender FROM Customer WHERE CustomerID = 1000);

GETDATE

SELECT GETDATE() as "Now"

IF

IF @gender IS NOT NULL
BEGIN
    { sql_statement | statement_block }
END

-- To define a statement block, use the control-of-flow keywords BEGIN and END.
IF Boolean_expression   
   { sql_statement | statement_block }   
[ ELSE   
   { sql_statement | statement_block } ]   

WHILE

DECLARE @cnt INT = 0;

WHILE @cnt < 3
BEGIN
    PRINT @cnt
    SET @cnt = @cnt + 1;
END;

SQLServer

这篇文章: 有用 无用
创建 2018-01-21 00:50:32 / 更新 2018-12-06 00:58:36