SQL Syntax Flashcards
What does it mean? “SET ANSI_NULLS ON”
Handling Nulls:
Equality comparison: NULL value will be evaluated to UNKNOWN.
Inequality comparison: NULL value will result in UNKNOWN.
Aggregate functions: NULL values are ignored.
ANSI NULLS is ON by Default
What does “SET QUOTED_IDENTIFIER ON” mean?
String literals: Double quotation marks (“”) are used to enclose string literals.
Identifiers: Double quotation marks (“”) are used to enclose identifiers such as table names, column names, and aliases that contain special characters or reserved keywords.
Stored Procedure General Format
CREATE PROCEDURE Procedure_Name
@Parameter DATA_TYPE
AS
BEGIN
xxxxxxxxxxx
END
GO
What are the three types of Functions?
1-Inline (Table Value)
2-Multi Statement (Table Value)
3-Scalar
Inline Function General Format
CREATE FUNCTION Function_Name (@Parameter DATA_TYPE)
RETURNS TABLE
AS
RETURN
xxxxxxxxxxxxxx
Multi Statement Function General Format
CREATE FUNCTION Function_Name (@Parameter DATA_TYPE)
RETURNS Table_Name TABLE ([Column_Name] DATA_TYPE)
<@Table_Variable_Name, sysname, @Table_Var> TABLE
AS
BEGIN
xxxxxxxxxxxxxxxxxx
RETURN
END
Scalar Function General Format
CREATE FUNCTION Function_Name (@Parameter DATA_TYPE)
RETURNS DATA_TYPE
AS
BEGIN
DECLARE @Variable_Name DATA_TYPE
RETURN @Variable_Name
END
Create Database
CREATE DATABASE database_name;
Create Table
CREATE TABLE table_name (
ID INT IDENTITY PRIMARY KEY,
column_name_1 DATA_TYPE NOT NULL,
column_name_2 DATA_TYPE NULL,
);
Bulk Insert from CSV file
BULK INSERT Employees
FROM ‘file_address.csv’
WITH (
FIELDTERMINATOR = ‘,’,
ROWTERMINATOR = ‘\n’,
FIRSTROW = 2
);