In my job we are following some formatting standards for
SQL. I have searched over the internet and found that every company is having their
own SQL formatting standards. But these are the very common standards which
every company is using. Below are the some examples to cover all the query.
Example of SELECT statement:
SELECT
ST.ColumnName1,
JT.ColumnName2,
SJT.ColumnName3
FROM
FirstTable FT
INNER JOIN
SecondTable ST
ON
FT.Id =
ST.Id
AND
FT.ColumnName = ST.ColumnName
INNER JOIN
ThirdTable TT
ON
ST.SourceTableID = TT.SourceTableID
AND
ST.Column3 = TT.Column4
WHERE
ST.SourceTableID
= X
AND
TT.Column3 = Y
Example of UPDATE statement:
UPDATE
TestTable
SET
ColumnName1 =
@value,
ColumnName2 =
@value2
WHERE
Condition1 = @test
Example of INSERT statement:
INSERT INTO TestTable
(
ColumnName1,
ColumnName2,
ColumnName3
)
VALUES
(
@value1,
@value2,
@value3
)
Example of IF Block statement:
IF (Condition)
BEGIN
--Logic
END
No comments:
Post a Comment