Session 1 - data types and tables Flashcards
CURRENT_TIMESTAMP
Returns DateTime datatype - LEGACY
GETDATE()
Returns DateTime
SYSDATETIME()
Returns datetime2
How to get name of day, month from a date
DATENAME(interval, DateTime)
ADDS AN INCREMENT TO A DATE (DAY, MONTH, YEAR)
DATEADD(INTERVAL, INCREMENT, DATETIME)
EXTRACTS THE INTERVAL FROM THE GIVEN DATE
DATEPART(INTERVAL, DATETIME)
SHOWS THE DIFFERENCE IN INTERVAL BETWEEN TWO DATES
DATEDIFF(INTERVAL, BEGIN DATE, END DATE)
CONVERT DATE TO STRING using convert
CONVERT(NVARCHAR(20), DATE, 101 or other number for dates)
Convert date time using parse
PARSE(‘DATE STRING’ AS DATE [USING ‘es-ES’]for other languages)
Convert date time to string using cast
FORMAT(CAST(DATE AS DATETIME), ‘dd-MM-yyyy’, ‘language’)
If you’re filtering on summarized data, use _____ otherwise use where
Having (vs where)
Default number of rows you can insert is _____
1000 rows (pertaining to defaults)
Database Diagrams can create _____ _____ between tables
foreign keys (pertaining to database diagrams)
Query order of operations
- FROM, including JOINS
- WHERE
- GROUP BY
- HAVING
- WINDOW functions
- SELECT
- DISTINCT
- UNION
- ORDER BY
- LIMIT and OFFSET
List all types of joins
INNER - RECORDS EXIST IN BOTH
LEFT (outer) - ALL RECORDS IN FIRST
RIGHT (outer) -ALL RECORDS IN LAST
FULL (outer) - ALL RECORDS FROM BOTH
Cross - A join that puts all rows in table A against all rows in table B (IE if table A has 3 rows 1,2,3 and table B has 3 rows A,B,C the result set would be 1,A, 1,B, 1,C, 2,A, 2,B, 2,C, etc.)
4 standard databases
Master
Tempdb
Model
Msdb
What is masterdb
Primary configuration database
Contains information on all the databases that exist on the server
physical database files and their locations.
SQL Server’s configuration settings
login account information.
What is tempdb
used as a store of:
internal objects, row versions, work tables, temporary tables, indexes.
Available for use to all participants connected to a SQL Server instance (it is a global resource)
What is model database
Template for all databases created on an instance of SQL Server.
Model is required because of TempDB.
Newly created user databases use the same recovery model as the model db
What is msdb
Used by SQL Server Agent for:
scheduling alerts
jobs
and by other features such as:
SQL Server Management Studio,
Service Broker
Database Mail.
backup-and-restore history
Convert Syntax
Convert(dataTypeToConvertTo, variableToConvert)
Cast Syntax
Cast(@myvar as DataType)
What is type used when working with SIN, COS, TAN, etc
Radians
What are the three functions for rounding
FLOOR
CEILING
ROUND