Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Tips:

group by non_aggrigate _column


name

Tips:
To filter group by result use having
condition(<,>,etc..)

use "varchar" in convert

SELECT INTO:
COLLECT DATA FROM VARIOUS TABLE AND
CREATE A NEW TABLE
PRIMARY KEY

CONSTRAINT NAME COLUMN NAME

CONSTRAINT TYPE
CAST: CAST(EXPRESSION AS DATATYPE)
Convert datype without specific format

CONVERT: CONVERT(DATATYPE,EXPRESSION,STYLE)
converting and formatting
column name
TRY_CONVERT:

TYR_CONVERT(DATATYPE,EXPRESSION)
TRY_CONVERT(DATATYPE,EXPRESSION,STYLE)

Tryconvert if convert succeed return the value


if not return the null

select convert(varchar,123456.12345,1)
default it is integer. interger dont have (',') we have
to convert as money to get coma(',')

select convert(varchar,cast(123456.12345 as money),1)


select convert(varchar,cast(123456.12345 as money),2)
CREATE TABLE:
table name

you dont need to enter value for HireDate and


Department bcus "DEFAULT"

I can overwrite
DEFAULT value
while using insert into

Example:Modify
table

table

table
table

table

table
DELETE:
wont work if the table already exist

will not work if table already exist

table name u want to create

Technique to create an empty table using select into:

if condition is true it creates a table.if not true it create a


strecture of table(only columns).no data in it
INSERT INTO:

Result:65 rows in
CustomerInvoiceTotals

Result:130 rows
CustomerInvoiceTotals
65+65
Item_stock item_sales

1st time running target table


source table

no need to mention target table name after 'update'

2nd time running

no need to mention target table name after "delete"

1st time execution:

2nd time execution: 3rd time execution:

You might also like