Virtual

networks

and

virtual

machines

in

Azure

July

minutes

to

read

Contributors

In

this

article

Network

interfaces

IP

addresses

Virtual

network

and

subnets

Network

security

groups

Load

balancers

VMs

Next

steps

When

you

create

an

Azure

virtual

machine

VM

you

must

create

a

virtual

network

VNet

or

use

an

existing

VNet

You

also

need

to

decide

how

your

VMs

are

intended

to

be

accessed

on

the

VNet

It

is

important

to

plan

before

creating

resources

and

make

sure

that

you

understand

the

limits

of

networking

resources

In

the

following

figure

VMs

are

represented

as

web

servers

and

database

servers

Each

set

of

VMs

are

assigned

to

separate

subnets

in

the

VNet

You

can

create

a

VNet

before

you

create

a

VM

or

you

can

as

you

create

a

VM

You

create

these

resources

to

support

communication

with

a

VM

Network

interfaces

IP

addresses

Virtual

network

and

subnets

In

addition

to

those

basic

resources

you

should

also

consider

these

optional

resources

Network

security

groups

Load

balancers

Network

interfaces

A

network

interface

NIC

is

the

interconnection

between

a

VM

and

a

virtual

network

VNet

A

VM

must

have

at

least

one

NIC

but

can

have

more

than

one

depending

on

the

size

of

the

VM

you

create

Learn

about

how

many

NICs

each

VM

size

supports

for

Windows

or

Linux

You

can

create

a

VM

with

multiple

NICs

and

add

or

remove

NICs

through

the

lifecycle

of

a

VM

Multiple

NICs

allow

a

VM

to

connect

to

different

subnets

and

send

or

receive

traffic

over

the

most

appropriate

interface

VMs

with

any

number

of

network

interfaces

can

exist

in

the

same

availability

set

up

to

the

number

supported

by

the

VM

size

Each

NIC

attached

to

a

VM

must

exist

in

the

same

location

and

subscription

as

the

VM

Each

NIC

must

be

connected

to

a

VNet

that

exists

in

the

same

Azure

location

and

subscription

as

the

NIC

You

can

change

the

subnet

a

VM

is

connected

to

after

its

created

but

you

can

not

change

the

VNet

Each

NIC

attached

to

a

VM

is

assigned

a

MAC

address

that

doesnt

change

until

the

VM

is

deleted

This

table

lists

the

methods

that

you

can

use

to

create

a

network

interface

Method

Description

Azure

portal

When

you

create

a

VM

in

the

Azure

portal

a

network

interface

is

automatically

created

for

you

you

can

not

use

a

NIC

you

create

separately

The

portal

creates

a

VM

with

only

one

NIC

If

you

want

to

create

a

VM

with

more

than

one

NIC

you

must

create

it

with

a

different

method

Azure

PowerShell

Use

NewAzureRmNetworkInterface

with

the

PublicIpAddressId

parameter

to

provide

the

identifier

of

the

public

IP

address

that

you

previously

created

Azure

CLI

To

provide

the

identifier

of

the

public

IP

address

that

you

previously

created

use

az

network

nic

create

with

the

publicipaddress

parameter

Template

Use

Network

Interface

in

a

Virtual

Network

with

Public

IP

Address

as

a

guide

for

deploying

a

network

interface

using

a

template

IP

addresses

You

can

assign

these

types

of

IP

addresses

to

a

NIC

in

Azure

Public

IP

addresses

Used

to

communicate

inbound

and

outbound

without

network

address

translation

NAT

with

the

Internet

and

other

Azure

resources

not

connected

to

a

VNet

Assigning

a

public

IP

address

to

a

NIC

is

optional

Public

IP

addresses

have

a

nominal

charge

and

theres

a

maximum

number

that

can

be

used

per

subscription

Private

IP

addresses

Used

for

communication

within

a

VNet

your

onpremises

network

and

the

Internet

with

NAT

You

must

assign

at

least

one

private

IP

address

to

a

VM

To

learn

more

about

NAT

in

Azure

read

Understanding

outbound

connections

in

Azure

You

can

assign

public

IP

addresses

to

VMs

or

internetfacing

load

balancers

You

can

assign

private

IP

addresses

to

VMs

and

internal

load

balancers

You

assign

IP

addresses

to

a

VM

using

a

network

interface

There

are

two

methods

in

which

an

IP

address

is

allocated

to

a

resource

dynamic

or

static

The

default

allocation

method

is

dynamic

where

an

IP

address

is

not

allocated

when

its

created

Instead

the

IP

address

is

allocated

when

you

create

a

VM

or

start

a

stopped

VM

The

IP

address

is

released

when

you

stop

or

delete

the

VM

To

ensure

the

IP

address

for

the

VM

remains

the

same

you

can

set

the

allocation

method

explicitly

to

static

In

this

case

an

IP

address

is

assigned

immediately

It

is

released

only

when

you

delete

the

VM

or

change

its

allocation

method

to

dynamic

This

table

lists

the

methods

that

you

can

use

to

create

an

IP

address

Method

Description

Azure

portal

By

default

public

IP

addresses

are

dynamic

and

the

address

associated

to

them

may

change

when

the

VM

is

stopped

or

deleted

To

guarantee

that

the

VM

always

uses

the

same

public

IP

address

create

a

static

public

IP

address

By

default

the

portal

assigns

a

dynamic

private

IP

address

to

a

NIC

when

creating

a

VM

You

can

change

this

IP

address

to

static

after

the

VM

is

created

Azure

PowerShell

You

use

NewAzureRmPublicIpAddress

with

the

AllocationMethod

parameter

as

Dynamic

or

Static

Azure

CLI

You

use

az

network

publicip

create

with

the

allocationmethod

parameter

as

Dynamic

or

Static

Template

Use

Network

Interface

in

a

Virtual

Network

with

Public

IP

Address

as

a

guide

for

deploying

a

public

IP

address

using

a

template

After

you

create

a

public

IP

address

you

can

associate

it

with

a

VM

by

assigning

it

to

a

NIC

Virtual

network

and

subnets

A

subnet

is

a

range

of

IP

addresses

in

the

VNet

You

can

divide

a

VNet

into

multiple

subnets

for

organization

and

security

Each

NIC

in

a

VM

is

connected

to

one

subnet

in

one

VNet

NICs

connected

to

subnets

same

or

different

within

a

VNet

can

communicate

with

each

other

without

any

extra

configuration

When

you

set

up

a

VNet

you

specify

the

topology

including

the

available

address

spaces

and

subnets

If

the

VNet

is

to

be

connected

to

other

VNets

or

onpremises

networks

you

must

select

address

ranges

that

dont

overlap

The

IP

addresses

are

private

and

cant

be

accessed

from

the

Internet

which

was

true

only

for

the

nonroutable

IP

addresses

such

as

or

Now

Azure

treats

any

address

range

as

part

of

the

private

VNet

IP

address

space

that

is

only

reachable

within

the

VNet

within

interconnected

VNets

and

from

your

onpremises

location

If

you

work

within

an

organization

in

which

someone

else

is

responsible

for

the

internal

networks

you

should

talk

to

that

person

before

selecting

your

address

space

Make

sure

there

is

no

overlap

and

let

them

know

the

space

you

want

to

use

so

they

dont

try

to

use

the

same

range

of

IP

addresses

By

default

there

is

no

security

boundary

between

subnets

so

VMs

in

each

of

these

subnets

can

talk

to

one

another

However

you

can

set

up

Network

Security

Groups

NSGs

which

allow

you

to

control

the

traffic

flow

to

and

from

subnets

and

to

and

from

VMs

This

table

lists

the

methods

that

you

can

use

to

create

a

VNet

and

subnets

Method

Description

Azure

portal

If

you

let

Azure

create

a

VNet

when

you

create

a

VM

the

name

is

a

combination

of

the

resource

group

name

that

contains

the

VNet

and

vnet

The

address

space

is

the

required

subnet

name

is

default

and

the

subnet

address

range

is

Azure

PowerShell

You

use

NewAzureRmVirtualNetworkSubnetConfig

and

NewAzureRmVirtualNetwork

to

create

a

subnet

and

a

VNet

You

can

also

use

AddAzureRmVirtualNetworkSubnetConfig

to

add

a

subnet

to

an

existing

VNet

Azure

CLI

The

subnet

and

the

VNet

are

created

at

the

same

time

Provide

a

subnetname

parameter

to

az

network

vnet

create

with

the

subnet

name

Template

The

easiest

way

to

create

a

VNet

and

subnets

is

to

download

an

existing

template

such

as

Virtual

Network

with

two

subnets

and

modify

it

for

your

needs

Network

security

groups

A

network

security

group

NSG

contains

a

list

of

Access

Control

List

ACL

rules

that

allow

or

deny

network

traffic

to

subnets

NICs

or

both

NSGs

can

be

associated

with

either

subnets

or

individual

NICs

connected

to

a

subnet

When

an

NSG

is

associated

with

a

subnet

the

ACL

rules

apply

to

all

the

VMs

in

that

subnet

In

addition

traffic

to

an

individual

NIC

can

be

restricted

by

associating

an

NSG

directly

to

a

NIC

NSGs

contain

two

sets

of

rules

inbound

and

outbound

The

priority

for

a

rule

must

be

unique

within

each

set

Each

rule

has

properties

of

protocol

source

and

destination

port

ranges

address

prefixes

direction

of

traffic

priority

and

access

type

All

NSGs

contain

a

set

of

default

rules

The

default

rules

can

not

be

deleted

but

because

they

are

assigned

the

lowest

priority

they

can

be

overridden

by

the

rules

that

you

create

When

you

associate

an

NSG

to

a

NIC

the

network

access

rules

in

the

NSG

are

applied

only

to

that

NIC

If

an

NSG

is

applied

to

a

single

NIC

on

a

multiNIC

VM

it

does

not

affect

traffic

to

the

other

NICs

You

can

associate

different

NSGs

to

a

NIC

or

VM

depending

on

the

deployment

model

and

the

subnet

that

a

NIC

or

VM

is

bound

to

Priority

is

given

based

on

the

direction

of

traffic

Be

sure

to

plan

your

NSGs

when

you

plan

your

VMs

and

VNet

This

table

lists

the

methods

that

you

can

use

to

create

a

network

security

group

Method

Description

Azure

portal

When

you

create

a

VM

in

the

Azure

portal

an

NSG

is

automatically

created

and

associated

to

the

NIC

the

portal

creates

The

name

of

the

NSG

is

a

combination

of

the

name

of

the

VM

and

nsg

This

NSG

contains

one

inbound

rule

with

a

priority

of

service

set

to

RDP

the

protocol

set

to

TCP

port

set

to

and

action

set

to

Allow

If

you

want

to

allow

any

other

inbound

traffic

to

the

VM

you

must

add

additional

rules

to

the

NSG

Azure

PowerShell

Use

NewAzureRmNetworkSecurityRuleConfig

and

provide

the

required

rule

information

Use

NewAzureRmNetworkSecurityGroup

to

create

the

NSG

Use

SetAzureRmVirtualNetworkSubnetConfig

to

configure

the

NSG

for

the

subnet

Use

SetAzureRmVirtualNetwork

to

add

the

NSG

to

the

VNet

Azure

CLI

Use

az

network

nsg

create

to

initially

create

the

NSG

Use

az

network

nsg

rule

create

to

add

rules

to

the

NSG

Use

az

network

vnet

subnet

update

to

add

the

NSG

to

the

subnet

Template

Use

Create

a

Network

Security

Group

as

a

guide

for

deploying

a

network

security

group

using

a

template

Load

balancers

Azure

Load

Balancer

delivers

high

availability

and

network

performance

to

your

applications

A

load

balancer

can

be

configured

to

balance

incoming

Internet

traffic

to

VMs

or

balance

traffic

between

VMs

in

a

VNet

A

load

balancer

can

also

balance

traffic

between

onpremises

computers

and

VMs

in

a

crosspremises

network

or

forward

external

traffic

to

a

specific

VM

The

load

balancer

maps

incoming

and

outgoing

traffic

between

the

public

IP

address

and

port

on

the

load

balancer

and

the

private

IP

address

and

port

of

the

VM

When

you

create

a

load

balancer

you

must

also

consider

these

configuration

elements

Frontend

IP

configuration

A

load

balancer

can

include

one

or

more

frontend

IP

addresses

otherwise

known

as

virtual

IPs

VIPs

These

IP

addresses

serve

as

ingress

for

the

traffic

Backend

address

pool

IP

addresses

that

are

associated

with

the

NIC

to

which

load

is

distributed

NAT

rules

Defines

how

inbound

traffic

flows

through

the

frontend

IP

and

distributed

to

the

backend

IP

Load

balancer

rules

Maps

a

given

frontend

IP

and

port

combination

to

a

set

of

backend

IP

addresses

and

port

combination

A

single

load

balancer

can

have

multiple

load

balancing

rules

Each

rule

is

a

combination

of

a

frontend

IP

and

port

and

backend

IP

and

port

associated

with

VMs

Probes

Monitors

the

health

of

VMs

When

a

probe

fails

to

respond

the

load

balancer

stops

sending

new

connections

to

the

unhealthy

VM

The

existing

connections

are

not

affected

and

new

connections

are

sent

to

healthy

VMs

This

table

lists

the

methods

that

you

can

use

to

create

an

internetfacing

load

balancer

Method

Description

Azure

portal

You

cant

currently

create

an

internetfacing

load

balancer

using

the

Azure

portal

Azure

PowerShell

To

provide

the

identifier

of

the

public

IP

address

that

you

previously

created

use

NewAzureRmLoadBalancerFrontendIpConfig

with

the

PublicIpAddress

parameter

Use

NewAzureRmLoadBalancerBackendAddressPoolConfig

to

create

the

configuration

of

the

backend

address

pool

Use

NewAzureRmLoadBalancerInboundNatRuleConfig

to

create

inbound

NAT

rules

associated

with

the

frontend

IP

configuration

that

you

created

Use

NewAzureRmLoadBalancerProbeConfig

to

create

the

probes

that

you

need

Use

NewAzureRmLoadBalancerRuleConfig

to

create

the

load

balancer

configuration

Use

NewAzureRmLoadBalancer

to

create

the

load

balancer

Azure

CLI

Use

az

network

lb

create

to

create

the

initial

load

balancer

configuration

Use

az

network

lb

frontendip

create

to

add

the

public

IP

address

that

you

previously

created

Use

az

network

lb

addresspool

create

to

add

the

configuration

of

the

backend

address

pool

Use

az

network

lb

inboundnatrule

create

to

add

NAT

rules

Use

az

network

lb

rule

create

to

add

the

load

balancer

rules

Use

az

network

lb

probe

create

to

add

the

probes

Template

Use

VMs

in

a

Load

Balancer

and

configure

NAT

rules

on

the

LB

as

a

guide

for

deploying

a

load

balancer

using

a

template

This

table

lists

the

methods

that

you

can

use

to

create

an

internal

load

balancer

Method

Description

Azure

portal

You

cant

currently

create

an

internal

load

balancer

using

the

Azure

portal

Azure

PowerShell

To

provide

a

private

IP

address

in

the

network

subnet

use

NewAzureRmLoadBalancerFrontendIpConfig

with

the

PrivateIpAddress

parameter

Use

to

create

the

configuration

of

the

backend

address

pool

Use

to

create

inbound

NAT

rules

associated

with

the

frontend

IP

configuration

that

you

created

Use

NewAzureRmLoadBalancerProbeConfig

to

create

the

probes

that

you

need

Use

NewAzureRmLoadBalancerRuleConfig

to

create

the

load

balancer

configuration

Use

NewAzureRmLoadBalancer

to

create

the

load

balancer

Azure

CLI

Use

the

az

network

lb

create

command

to

create

the

initial

load

balancer

configuration

To

define

the

private

IP

address

use

az

network

lb

frontendip

create

with

the

privateipaddress

parameter

Use

az

network

lb

addresspool

create

to

add

the

configuration

of

the

backend

address

pool

Use

az

network

lb

inboundnatrule

create

to

add

NAT

rules

Use

az

network

lb

rule

create

to

add

the

load

balancer

rules

Use

az

network

lb

probe

create

to

add

the

probes

Template

Use

VMs

in

a

Load

Balancer

and

configure

NAT

rules

on

the

LB

as

a

guide

for

deploying

a

load

balancer

using

a

template

VMs

VMs

can

be

created

in

the

same

VNet

and

they

can

connect

to

each

other

using

private

IP

addresses

They

can

connect

even

if

they

are

in

different

subnets

without

the

need

to

configure

a

gateway

or

use

public

IP

addresses

To

put

VMs

into

a

VNet

you

create

the

VNet

and

then

as

you

create

each

VM

you

assign

it

to

the

VNet

and

subnet

VMs

acquire

their

network

settings

during

deployment

or

startup

VMs

are

assigned

an

IP

address

when

they

are

deployed

If

you

deploy

multiple

VMs

into

a

VNet

or

subnet

they

are

assigned

IP

addresses

as

they

boot

up

You

can

also

allocate

a

static

IP

to

a

VM

If

you

allocate

a

static

IP

you

should

consider

using

a

specific

subnet

to

avoid

accidentally

reusing

a

static

IP

for

another

VM

If

you

create

a

VM

and

later

want

to

migrate

it

into

a

VNet

it

is

not

a

simple

configuration

change

You

must

redeploy

the

VM

into

the

VNet

The

easiest

way

to

redeploy

is

to

delete

the

VM

but

not

any

disks

attached

to

it

and

then

recreate

the

VM

using

the

original

disks

in

the

VNet

This

table

lists

the

methods

that

you

can

use

to

create

a

VM

in

a

VNet

Method

Description

Azure

portal

Uses

the

default

network

settings

that

were

previously

mentioned

to

create

a

VM

with

a

single

NIC

To

create

a

VM

with

multiple

NICs

you

must

use

a

different

method

Azure

PowerShell

Includes

the

use

of

AddAzureRmVMNetworkInterface

to

add

the

NIC

that

you

previously

created

to

the

VM

configuration

Azure

CLI

Create

and

connect

a

VM

to

a

Vnet

subnet

and

NIC

that

build

as

individual

steps

Template

Use

Very

simple

deployment

of

a

Windows

VM

as

a

guide

for

deploying

a

VM

using

a

template

Next

steps

For

VMspecific

steps

on

how

to

manage

Azure

virtual

networks

for

VMs

see

the

Windows

or

Linux

tutorials

There

are

also

tutorials

on

how

to

load

balance

VMs

and

create

highly

available

applications

for

Windows

or

Linux

Learn

how

to

configure

userdefined

routes

and

IP

forwarding

Learn

how

to

configure

VNet

to

VNet

connections

Learn

how

to

Troubleshoot

routes

B I O B I O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O B O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O B O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O


How

to

Set

a

Property

After

Animating

It

with

a

Storyboard

March

minutes

to

read

Contributors

all

In

some

cases

it

might

appear

that

you

cant

change

the

value

of

a

property

after

it

has

been

animated

Example

In

the

following

example

a

Storyboard

is

used

to

animate

the

color

of

a

SolidColorBrush

The

storyboard

is

triggered

when

the

button

is

clicked

The

Completed

event

is

handled

so

that

the

program

is

notified

when

the

ColorAnimation

completes

Button

ContentAnimate

and

Then

Set

Example

ButtonBackground

SolidColorBrush

ColorRed

ButtonBackground

ButtonTriggers

EventTrigger

RoutedEventButtonClick

BeginStoryboard

Storyboard

ColorAnimation

StoryboardTargetPropertyColor

FromRed

ToYellow

FillBehaviorHoldEnd

Storyboard

BeginStoryboard

EventTrigger

ButtonTriggers

Button

Example

After

the

ColorAnimation

completes

the

program

attempts

to

change

the

brushs

color

to

blue

private

void

sender

EventArgs

e

Does

not

appear

to

have

any

effect

the

brush

remains

yellow

ColorsBlue

The

previous

code

doesnt

appear

to

do

anything

the

brush

remains

yellow

which

is

the

value

supplied

by

the

ColorAnimation

that

animated

the

brush

The

underlying

property

value

the

base

value

is

actually

changed

to

blue

However

the

effective

or

current

value

remains

yellow

because

the

ColorAnimation

is

still

overriding

the

base

value

If

you

want

the

base

value

to

become

the

effective

value

again

you

must

stop

the

animation

from

influencing

the

property

There

are

three

ways

to

do

this

with

storyboard

animations

Set

the

animations

FillBehavior

property

to

Remove

the

entire

Storyboard

Remove

the

animation

from

the

individual

property

Set

the

animations

FillBehavior

property

to

Stop

By

setting

FillBehavior

to

Stop

you

tell

the

animation

to

stop

affecting

its

target

property

after

it

reaches

the

end

of

its

active

period

Button

ContentAnimate

and

Then

Set

Example

ButtonBackground

SolidColorBrush

ColorRed

ButtonBackground

ButtonTriggers

EventTrigger

RoutedEventButtonClick

BeginStoryboard

Storyboard

ColorAnimation

StoryboardTargetPropertyColor

FromRed

ToYellow

FillBehaviorStop

Storyboard

BeginStoryboard

EventTrigger

ButtonTriggers

Button

private

void

sender

EventArgs

e

This

appears

to

work

the

brush

changes

to

blue

ColorsBlue

Remove

the

entire

storyboard

By

using

a

RemoveStoryboard

trigger

or

the

StoryboardRemove

method

you

tell

the

storyboard

animations

to

stop

affecting

their

target

properties

The

difference

between

this

approach

and

setting

the

FillBehavior

property

is

that

you

can

remove

the

storyboard

at

anytime

while

the

FillBehavior

property

only

has

an

effect

when

the

animation

reaches

the

end

of

its

active

period

Button

ContentAnimate

and

Then

Set

Example

ButtonBackground

SolidColorBrush

ColorRed

ButtonBackground

ButtonTriggers

EventTrigger

RoutedEventButtonClick

BeginStoryboard

NameMyBeginStoryboard

Storyboard

xNameMyStoryboard

ColorAnimation

StoryboardTargetPropertyColor

FromRed

ToYellow

FillBehaviorHoldEnd

Storyboard

BeginStoryboard

EventTrigger

ButtonTriggers

Button

private

void

sender

EventArgs

e

This

appears

to

work

the

brush

changes

to

blue

ColorsBlue

Remove

an

animation

from

an

individual

property

Another

technique

to

stop

an

animation

from

affecting

a

property

is

to

use

the

BeginAnimationDependencyProperty

AnimationTimeline

method

of

the

object

being

animated

Specify

the

property

being

animated

as

the

first

parameter

and

as

the

second

Button

ContentAnimate

and

Then

Set

Example

ButtonBackground

SolidColorBrush

ColorRed

ButtonBackground

ButtonTriggers

EventTrigger

RoutedEventButtonClick

BeginStoryboard

Storyboard

ColorAnimation

StoryboardTargetPropertyColor

FromRed

ToYellow

FillBehaviorHoldEnd

Storyboard

BeginStoryboard

EventTrigger

ButtonTriggers

Button

private

void

sender

EventArgs

e

This

appears

to

work

the

brush

changes

to

blue

ColorsBlue

This

technique

also

works

for

nonstoryboard

animations

See

Also

FillBehavior

StoryboardRemove

RemoveStoryboard

Animation

Overview

Property

Animation

Techniques

Overview

O O O O B O O O O O B O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O B O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O B O O O O O B O O O O B O O O O O O B O O O O B O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O B O O O O O O O O O O O O O O O O B O O O O O O B O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O B O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O


Entering Criteria in Filters June 3 2016 2 minutes to read Contributors In this article See Also When you enter criteria you can use all the numbers and letters that you can normally use in the field In addition you can use some special symbols or mathematical expressions Here are the available formats Symbol Meaning Sample Expression Records Displayed Equal to 377 Number 377 BLUE Those with the BLUE code for example the BLUE warehouse code 22 A datetime from 22current monthcurrent year 00000 to 22current monthcurrent year 225959 22 10 An exact datetime 220101 100000 Interval 11002100 Numbers 1100 through 2100 2500 Up to and including 2500 12 31 00 Dates up to and including 12 31 00 P8 Information for accounting period 8 and thereafter 23 From the beginning of time until 23current monthcurrent year 235959 23 From 23current monthcurrent year 00000 until the end of time 2223 From 22current monthcurrent year 00000 until 23current monthcurrent year 235959 Eitheror 12001300 Those with number 1200 or 1300 And 20001000 Numbers that are less than 2000 and greater than 1000 The sign can not be used by itself with numbers because no record can have two numbers Not equal to 0 All numbers except 0 Greater than 1200 Numbers greater than 1200 Greater than or equal to 1200 Numbers greater than or equal to 1200 Less than 1200 Numbers less than 1200 Less than or equal to 1200 Numbers less than or equal to 1200 An indefinite number of unknown characters Co Texts that contain Co Co Texts that end with Co Co Texts that begin with Co One unknown character Hansn Texts such as Hansen or Hanson Calculate before rest 301020 Those with number 30 or with a number from 10 through 20 the result of the calculation within the parentheses Ignore case either uppercase or lowercase allowed location Texts such as LOCATION location or Location You can also combine the various format expressions 599981008490 Include any records with the number 5999 or a number from the interval 8100 through 8490 12991400 Include records with a number less than or equal to 1299 or a number equal to 1400 or greater all numbers except 1300 through 1399 50100 Include records with numbers that are greater than 50 and less than 100 numbers 51 through 99 CD Texts containing both C and D co Texts containing co CO Co cO such as cot cope and incorporated CO cO Co or co must be present followed by at least one character but there can be an indefinite number of characters before and after these and case is unimportant Note It is important that you enter only meaningful filters For example it is possible to specify an interval that does not exist and the program can not check this for you In order to enter meaningful filters you must know the sorting rules followed by this program See Also Understanding Query Filters

B I O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O B

entering criteria
filters
mathematical expressions


Create unique Project IDs for my projects in Project Online February 8 2018 3 minutes to read Contributors In this article Configure Project ID settings when creating a new Enterprise Project Type in Project Online Best practices When creating new projects in Project Online some companies may want to create a unique Project ID to associate with each project This allows users to reference each project by a unique Project ID instead of a project name since project names can be changed A Project admin can configure Project Online to generate a unique Project ID for each new project through Enterprise Project Type EPT configuration settings You can configure the EPTs Project ID settings so that when a new project is created through the EPT it will generate a unique Project ID for the new project based on the naming properties you configured Configure Project ID settings when creating a new Enterprise Project Type in Project Online On the Project Web App home page select Server Settings On the Server Settings page in the Workflow and Project Detail Pages section click Enterprise Project Types Select New Enterprise Project Type On the New Enterprise Project Types page in the Name field specify a name for the Enterprise Project Type you want to create For example if the EPT is going to be used by the Finance Department for high risk projects you could enter Finance Dept High Risk In the Description field type a description of the EPT For example Use this EPT to create highrisk projects for Finance In the Project ID section you need to enter information that will be used to create a unique Project ID for your projects that are created through the EPT template In the Prefix field you can enter characters that will be at the start of each generated Project ID For example you may want the Project ID for projects created through the Finance Department EPT to begin with FIN_ This field is optional In the Starting Number field enter a number that will serve as a starting point for Project IDs that are going to be generated for this EPT For example enter 10001 if you want the first Project ID to be 10001 This field is required In the Postfix field you can enter characters that can be used to append your Project IDs that are generated by this EPT For example if this EPT is used to create only highrisk projects for the Finance department you could enter _HR This field is optional In the Minimum Digit Padding field enter a number of digits that you want to have for newly generated Project IDs For example if you enter 3 and have a Starting Number of 1 then the first three Project IDs that will be generated are 001 002 and 003 If you enter 5 with a Starting Number of 1 the first three Project IDs that will be generated are 00001 00002 and 00003 For example with the sample settings used in the procedure above the Project IDs generated through the Finance Dept High Risk EPT will be FIN_10001_HR FIN_10002_HR FIN_10003_HR Etc Note While the Prefix and Postfix fields are optional the easiest way to ensure uniqueness across all EPTs is to make sure you provide either a unique Prefix or Postfix Best practices For larger organizations it is a good idea for the Project admins or PMO to agree upon a Project ID naming convention and a numeric range to ensure uniqueness Additionally it is also a good idea to document the EPT settings for reference For example Prefix Starting Number Postfix Minimum Digit Padding Used to make projects for this team Fin_ 10001 _HR 1 Finance Team Highrisk projects IT_ 10001 1 Information Technologies Team MKT_ 10001 1 Marketing Team Other best practices to consider It is important that you come up with a naming convention on how you want to segment your Project IDs before starting the configuration of your EPTs to ensure uniqueness across different EPTs If youre planning to update the Project ID value programmatically via the Clientside Object Model CSOM the uniqueness of the value will have to be managed by your custom code to avoid duplicates A Project ID can be edited if it is added to a Project Detail page You can use this approach to perform adhoc edits of the Project ID value if needed As always ensure that there is a standardized naming convention in place to ensure uniqueness of your Project IDs if you need to make adhoc changes

O O O O O O O O B I O O O O O O O O O O O O B I O O O O O O O O O B I O O O O O O O B I O O O O O O O O B I O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O B I O O O O B I O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O B I O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O


Server Memory Server Configuration Options November 26 2017 9 minutes to read Contributors all APPLIES TO SQL Server Azure SQL Database Azure SQL Data Warehouse Parallel Data Warehouse Use the two server memory options min server memory and max server memory to reconfigure the amount of memory in megabytes that is managed by the SQL Server Memory Manager for a SQL Server process used by an instance of SQL Server The default setting for min server memory is 0 and the default setting for max server memory is 2147483647 megabytes MB By default SQL Server can change its memory requirements dynamically based on available system resources For more information see dynamic memory management The minimum memory amount allowable for max server memory is 128 MB Important Setting max server memory value too high can cause a single instance of SQL Server might have to compete for memory with other SQL Server instances hosted on the same host However setting this value too low could cause significant memory pressure and performance problems Setting max server memory to the minimum value can even prevent SQL Server from starting If you can not start SQL Server after changing this option start it using the f startup option and reset max server memory to its previous value For more information see Database Engine Service Startup Options SQL Server can use memory dynamically however you can set the memory options manually and restrict the amount of memory that SQL Server can access Before you set the amount of memory for SQL Server determine the appropriate memory setting by subtracting from the total physical memory the memory required for the OS memory allocations not controlled by the max_server_memory setting and any other instances of SQL Server and other system uses if the computer is not wholly dedicated to SQL Server This difference is the maximum amount of memory you can assign to the current SQL Server instance Setting the memory options manually The server options min server memory and max server memory can be set to span a range of memory values This method is useful for system or database administrators to configure an instance of SQL Server in conjunction with the memory requirements of other applications or other instances of SQL Server that run on the same host Note The min server memory and max server memory options are advanced options If you are using the sp_configure system stored procedure to change these settings you can change them only when show advanced options is set to 1 These settings take effect immediately without a server restart Use min_server_memory to guarantee a minimum amount of memory available to the SQL Server Memory Manager for an instance of SQL Server SQL Server will not immediately allocate the amount of memory specified in min server memory on startup However after memory usage has reached this value due to client load SQL Server can not free memory unless the value of min server memory is reduced For example when several instances of SQL Server can exist concurrently in the same host set the min_server_memory parameter instead of max_server_memory for the purpose of reserving memory for an instance Also setting a min_server_memory value is essential in a virtualized environment to ensure memory pressure from the underlying host does not attempt to deallocate memory from the buffer pool on a guest SQL Server virtual machine VM beyond what is needed for acceptable performance Note SQL Server is not guaranteed to allocate the amount of memory specified in min server memory If the load on the server never requires allocating the amount of memory specified in min server memory SQL Server will run with less memory Use max_server_memory to guarantee the OS does not experience detrimental memory pressure To set max server memory configuration monitor overall consumption of the SQL Server process in order to determine memory requirements To be more accurate with these calculations for a single instance From the total OS memory reserve 1GB4GB to the OS itself Then subtract the equivalent of potential SQL Server memory allocations outside the max server memory control which is comprised of stack size 1 calculated max worker threads 2 g startup parameter 3 or 256MB by default if g is not set What remains should be the max_server_memory setting for a single instance setup 1 Refer to the Memory Management Architecture guide for information on thread stack sizes per architecture 2 Refer to the documentation page on how to Configure the max worker threads Server Configuration Option for information on the calculated default worker threads for a given number of affinitized CPUs in the current host 3 Refer to the documentation page on Database Engine Service Startup Options for information on the g startup parameter How to configure memory options using SQL Server Management Studio Use the two server memory options min server memory and max server memory to reconfigure the amount of memory in megabytes managed by the SQL Server Memory Manager for an instance of SQL Server By default SQL Server can change its memory requirements dynamically based on available system resources Procedure for configuring a fixed amount of memory not recommended To set a fixed amount of memory In Object Explorer rightclick a server and select Properties Click the Memory node Under Server Memory Options enter the same amount that you want for Minimum server memory and Maximum server memory Use the default settings to allow SQL Server to change its memory requirements dynamically based on available system resources It is recommended to set a max server memory as detailed above Lock Pages in Memory LPIM This Windows policy determines which accounts can use a process to keep data in physical memory preventing the system from paging the data to virtual memory on disk Locking pages in memory may keep the server responsive when paging memory to disk occurs The Lock Pages in Memory option is set to ON in instances of SQL Server Standard edition and higher when the account with privileges to run sqlservrexe has been granted the Windows Lock Pages in Memory LPIM user right To disable the Lock Pages In Memory option for SQL Server remove the Lock Pages in Memory user right for the account with privileges to run sqlservrexe the SQL Server startup account startup account Setting this option does not affect SQL Server dynamic memory management allowing it to expand or shrink at the request of other memory clerks When using the Lock Pages in Memory user right it is recommended to set an upper limit for max server memory as detailed above Important Setting this option should only be used when necessary namely if there are signs that sqlservr process is being paged out In this case error 17890 will be reported in the Errorlog resembling the below example A significant part of sql server process memory has been paged out This may result in a performance degradation Duration seconds Working set KB committed KB memory utilization Starting with SQL Server 2012 11x trace flag 845 is not needed for Standard Edition to use Locked Pages To enable Lock Pages in Memory To enable the lock pages in memory option On the Start menu click Run In the Open box type gpeditmsc The Group Policy dialog box opens On the Group Policy console expand Computer Configuration and then expand Windows Settings Expand Security Settings and then expand Local Policies Select the User Rights Assignment folder The policies will be displayed in the details pane In the pane doubleclick Lock pages in memory In the Local Security Policy Setting dialog box add the account with privileges to run sqlservrexe the SQL Server startup account Running multiple instances of SQL Server When you are running multiple instances of the Database Engine there are three approaches you can use to manage memory Use max server memory to control memory usage as detailed above Establish maximum settings for each instance being careful that the total allowance is not more than the total physical memory on your machine You might want to give each instance memory proportional to its expected workload or database size This approach has the advantage that when new processes or instances start up free memory will be available to them immediately The drawback is that if you are not running all of the instances none of the running instances will be able to utilize the remaining free memory Use min server memory to control memory usage as detailed above Establish minimum settings for each instance so that the sum of these minimums is 12 GB less than the total physical memory on your machine Again you may establish these minimums proportionately to the expected load of that instance This approach has the advantage that if not all instances are running at the same time the ones that are running can use the remaining free memory This approach is also useful when there is another memoryintensive process on the computer since it would insure that SQL Server would at least get a reasonable amount of memory The drawback is that Do nothing not recommended The first instances presented with a workload will tend to allocate all of memory Idle instances or instances started later may end up running with only a minimal amount of memory available SQL Server makes no attempt to balance memory usage across instances All instances will however respond to Windows Memory Notification signals to adjust the size of their memory footprint Windows does not balance memory across applications with the Memory Notification API It merely provides global feedback as to the availability of memory on the system You can change these settings without restarting the instances so you can easily experiment to find the best settings for your usage pattern Providing the maximum amount of memory to SQL Server Memory can be configured up to the process virtual address space limit in all SQL Server editions For more information see Memory Limits for Windows and Windows Server Releases Examples Example A The following example sets the max server memory option to 4 GB sp_configure show advanced options 1 GO RECONFIGURE GO sp_configure max server memory 4096 GO RECONFIGURE GO Example B Determining Current Memory Allocation The following query returns information about currently allocated memory SELECT physical_memory_in_use_kb1024 AS sql_physical_memory_in_use_MB large_page_allocations_kb1024 AS sql_large_page_allocations_MB locked_page_allocations_kb1024 AS sql_locked_page_allocations_MB virtual_address_space_reserved_kb1024 AS sql_VAS_reserved_MB virtual_address_space_committed_kb1024 AS sql_VAS_committed_MB virtual_address_space_available_kb1024 AS sql_VAS_available_MB page_fault_count AS sql_page_fault_count memory_utilization_percentage AS sql_memory_utilization_percentage process_physical_memory_low AS sql_process_physical_memory_low process_virtual_memory_low AS sql_process_virtual_memory_low FROM sysdm_os_process_memory See Also Memory Management Architecture Guide Monitor and Tune for Performance RECONFIGURE TransactSQL Server Configuration Options SQL Server sp_configure TransactSQL Database Engine Service Startup Options Editions and supported features of SQL Server 2016 Editions and supported features of SQL Server 2017 Editions and supported features of SQL Server 2017 on Linux Memory Limits for Windows and Windows Server Releases

B I I I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I I O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I I O O O O O O B I I I O O O O O O B I I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I I O O O B I I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O

server memory server configuration options


Set up logical networks in the VMM fabric November 6 2017 6 minutes to read Contributors In this article Before you start Create logical networks automatically Create logical networks manually Next steps Read this article to learn how to create logical networks in System Center Virtual Machine Manager VMM You have different types of networks in your organization including corporate networks management networks and others In VMM each of these networks is defined as a logical network Logical networks are logical objects that mirror your physicals networks When you create logical networks you assign them properties that match your physical environment You specify the type of network the associated network sites associated and the static address pools if youre not using DCHP to assign IP addresses to VMs you create in the network sites You also specify whether networks are isolated physically or virtually using network virtualization and virtual LANs VLANs You use logical networks when you provision virtualization hosts in the VMM fabric You associate physical adapters on hosts with logical networks VMM virtual machine VM networks are based on logical networks VM networks provide an interface through which VMs connect to a logical network A logical network can have a single or multiple VM networks mapped to it Before you start Before you start its important to understand how logical networks work in VMM Automatic logical networks By default VMM creates logical networks automatically When you provision a host in the VMM fabric and theres no VMM logical network associated with a physical network adapter on that host VMM automatically creates a logical network and associates it with an adapter By default for the logical network VMM first DNS suffix label of the connectionspecific DNS suffix By default VMM also creates a VM network configured with No isolation Manual logical networks When you create a logical network manually you specify Network type You specify whether the network is isolated or not and if it is how its isolated Then when you create VM networks based on the logical network theyll be created with the type of network you specified No isolation This is the simplest type of network model that specifies theres just a single network within which machines can connect to each other with no need to isolate these machines from each other VM networks in VMM provide an interface through which VMs connect to a logical network and in a no isolation model youll have a single VM network mapped to a logical network Isolation More often youll want to isolate networks from each other For example you might want to isolate networks that have different purposes or you might be a provider who wants to host workloads for multiple tenants on a single logical network with isolation for each tenant In this case youll have multiple VM networks mapped to a logical network VM networks mapped to a logical network can be isolated using VLANsprivate VLANs or network virtualization Note that A typical setup might be an infrastructure network with no isolation or VLAN isolation a load balancer backend and internet facing network with PVLAN and tenant networks with isolation using network virtualization You can only use one type of isolation on a single logical network If you do need this youll need multiple logical networks Theres a practical limit of 2000 tenants and 4000 VM networks for a single VMM server Network sites If your organization has different locations and datacenters you can include information about those sites in your logical network settings For example you could specify a New York site with and IP subnet andor VLAN settings and then a London site with different IPVLAN settings You can then assign IP address to VMs based on network location and VLAN settings Note that You need to assign an IP subnet to a site if VMM is going to distribute static IP addresses to VMs in the site If youre using DHCP you dont need a subnet You need to configure a VLAN if ones used in your physical site If youre not using VLANs and youre using DHCP you dont need to define network sites in your logical network Create logical networks automatically If you want VMM to automatically create logical networks and VM networks you can specify how VMM determines the logical network name Click Settings General Doubleclick Network Settings Configure the Logical network matching setting Note that For HyperV hosts you can use the entire DNS suffix label or the first one For example if the DNS suffix is corpcontosocom the logical network will be corpcontosocom or just corp This isnt supported for VMware hosts For HyperV and VMware hosts you can select the network connection name or the virtual network switch name the name of the virtual network switch to which the physical adapter of the host is bound By default VMware hosts use the virtual network switch option You can also specify a fallback option if the first logical matching fails If you dont want VMM to create logical and VM networks automatically you can disable the global setting Click Settings General and doubleclick Network Settings Clear Create logical networks automatically Create logical networks manually Fabric Home Show Fabric Resources In Fabric expand Networking Logical Networks Home Create Create Logical Network In Create Logical Network Wizard Name specify a name and description Specify how you want to isolate VM networks associated with this logical network If you want to have multiple VM networks associated with the logical network and isolate them using network virtualization click One connected network Allow new VM networks created on this logical network to use network virtualization If you want to have multiple VM networks associated with the logical network and isolate them using a VLANPVLAN select VLANbased independent networks or Private VLAN PVLAN networks If you dont want to isolate networks in the logical network click One connected network Create a VM network with the same name to allow virtual machines to access this logical network directly With this setting youll have a single VM network associated with your logical network If youve deployed a Microsoft network Controller in the VMM fabric you can select to have the logical network managed by the network controller In Network Site add network sites to the logical network If you dont need to create network sites click DHCP no VLAN If youre using DHCP to allocate IP addresses and you dont have VLANs you dont need a network site Note that VMM automatically suggests a site name Any network name shouldnt be longer than 64 characters Static IP If youre using static IP addresses create at least one network site and associate at least one IP subnet with it VLAN If youre using VLANs with static IP addressing create corresponding network site for the VLAN and subnet pairs If youre using DHCP create corresponding network sites for VLAN information only Network virtualization If youre using network virtualization create at least one network site with an associated IP subnet so that the logical network has an IP address pool Load balancer If the logical network will contain a load balancer create at least one network site with an associated IP subnet If youre using an external network managed by a vendor network management console or virtual switch extension manager outside VMM you can configure settings in the vendor conole and import them into VMM In Host groups that can use this network site select each host group to which you want to make the logical network available In Associated VLANs and IP subnets click Insert Row to specify the settings that you want to assign to the network site If you selecting PVLAN youll need to add a SecondaryVLAN for each VLAN Ensure that the VLANs and subnets are available in your physical network If you leave the VLAN field empty VMM assigns a value of 0 to indicate that VLANs arent used In trunk mode 0 indicates native VLAN In Summary review the settings and click Finish When the job shows as Completed verify the logical network in Logical Networks and IP Pools Next steps If you created network sites and associated one or more IP subnets with them youre not using DHCP you can create static IP address pools from those subnets Then VMM can automatically allocate IP addresses to VMs in the network site Set up IP address pools

O O B I O O B I O O O O O O O O O O O O O O O B I O O B I O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O B I O O O O O O O B I O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O B I O O O O B I O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O B I O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O


last aggregation On this page Definition Behavior Example Definition last Returns the value that results from applying an expression to the last document in a group of documents that share the same group by a field Only meaningful when documents are in a defined order last is only available in the group stage last has the following syntax copy copied last expression For more information on expressions see Expressions Behavior When using last in a group stage the group stage should follow a sort stage to have the input documents in a defined order Note Although the sort stage passes ordered documents as input to the group stage group is not guaranteed to maintain this sort order in its own output Example Consider a sales collection with the following documents copy copied _id 1 item abc date ISODate 20140101T080000Z price 10 quantity 2 _id 2 item jkl date ISODate 20140203T090000Z price 20 quantity 1 _id 3 item xyz date ISODate 20140203T090500Z price 5 quantity 5 _id 4 item abc date ISODate 20140215T080000Z price 10 quantity 10 _id 5 item xyz date ISODate 20140215T090500Z price 5 quantity 10 _id 6 item xyz date ISODate 20140215T120510Z price 5 quantity 5 _id 7 item xyz date ISODate 20140215T141212Z price 5 quantity 10 The following operation first sorts the documents by item and date and then in the following group stage groups the now sorted documents by the item field and uses the last accumulator to compute the last sales date for each item copy copied db sales aggregate sort item 1 date 1 group _id item lastSalesDate last date The operation returns the following results copy copied _id xyz lastSalesDate ISODate 20140215T141212Z _id jkl lastSalesDate ISODate 20140203T090000Z _id abc lastSalesDate ISODate 20140215T080000Z

O B O O O O B O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O

aggregation
applying an expression
behavior


Hierarchical Queries If a table contains hierarchical data then you can select rows in a hierarchical order using the hierarchical query clause hierarchical_query_clause Description of the illustration hierarchical_query_clausegif START WITH specifies the root rows of the hierarchy CONNECT BY specifies the relationship between parent rows and child rows of the hierarchy The NOCYCLE parameter instructs Oracle Database to return rows from a query even if a CONNECT BY LOOP exists in the data Use this parameter along with the CONNECT_BY_ISCYCLE pseudocolumn to see which rows contain the loop Please refer to CONNECT_BY_ISCYCLE Pseudocolumn for more information In a hierarchical query one expression in condition must be qualified with the PRIOR operator to refer to the parent row For example PRIOR expr expr or expr PRIOR expr If the CONNECT BY condition is compound then only one condition requires the PRIOR operator although you can have multiple PRIOR conditions For example CONNECT BY last_name King AND PRIOR employee_id manager_id CONNECT BY PRIOR employee_id manager_id and PRIOR account_mgr_id customer_id PRIOR is a unary operator and has the same precedence as the unary and arithmetic operators It evaluates the immediately following expression for the parent row of the current row in a hierarchical query PRIOR is most commonly used when comparing column values with the equality operator The PRIOR keyword can be on either side of the operator PRIOR causes Oracle to use the value of the parent row in the column Operators other than the equal sign are theoretically possible in CONNECT BY clauses However the conditions created by these other operators can result in an infinite loop through the possible combinations In this case Oracle detects the loop at run time and returns an error Both the CONNECT BY condition and the PRIOR expression can take the form of an uncorrelated subquery However the PRIOR expression can not refer to a sequence That is CURRVAL and NEXTVAL are not valid PRIOR expressions You can further refine a hierarchical query by using the CONNECT_BY_ROOT operator to qualify a column in the select list This operator extends the functionality of the CONNECT BY PRIOR condition of hierarchical queries by returning not only the immediate parent row but all ancestor rows in the hierarchy See Also CONNECT_BY_ROOT for more information about this operator and Hierarchical Query Examples Oracle processes hierarchical queries as follows A join if present is evaluated first whether the join is specified in the FROM clause or with WHERE clause predicates The CONNECT BY condition is evaluated Any remaining WHERE clause predicates are evaluated Oracle then uses the information from these evaluations to form the hierarchy using the following steps Oracle selects the root rows of the hierarchythose rows that satisfy the WITH condition Oracle selects the child rows of each root row Each child row must satisfy the condition of the CONNECT BY condition with respect to one of the root rows Oracle selects successive generations of child rows Oracle first selects the children of the rows returned in step 2 and then the children of those children and so on Oracle always selects children by evaluating the CONNECT BY condition with respect to a current parent row If the query contains a WHERE clause without a join then Oracle eliminates all rows from the hierarchy that do not satisfy the condition of the WHERE clause Oracle evaluates this condition for each row individually rather than removing all the children of a row that does not satisfy the condition Oracle returns the rows in the order shown in Figure 91 In the diagram children appear below their parents For an explanation of hierarchical trees see Figure 31 Hierarchical Tree Figure 91 Hierarchical Queries Description of Figure 91 Hierarchical Queries To find the children of a parent row Oracle evaluates the PRIOR expression of the CONNECT BY condition for the parent row and the other expression for each row in the table Rows for which the condition is true are the children of the parent The CONNECT BY condition can contain other conditions to further filter the rows selected by the query The CONNECT BY condition can not contain a subquery If the CONNECT BY condition results in a loop in the hierarchy then Oracle returns an error A loop occurs if one row is both the parent or grandparent or direct ancestor and a child or a grandchild or a direct descendent of another row Note In a hierarchical query do not specify either ORDER BY or GROUP BY as they will destroy the hierarchical order of the CONNECT BY results If you want to order rows of siblings of the same parent then use the ORDER SIBLINGS BY clause See order_by_clause Hierarchical Query Examples CONNECT BY Example The following hierarchical query uses the CONNECT BY clause to define the relationship between employees and managers SELECT employee_id last_name manager_id FROM employees CONNECT BY PRIOR employee_id manager_id EMPLOYEE_ID LAST_NAME MANAGER_ID 101 Kochhar 100 108 Greenberg 101 109 Faviet 108 110 Chen 108 111 Sciarra 108 112 Urman 108 113 Popp 108 200 Whalen 101 LEVEL Example The next example is similar to the preceding example but uses the LEVEL pseudocolumn to show parent and child rows SELECT employee_id last_name manager_id LEVEL FROM employees CONNECT BY PRIOR employee_id manager_id EMPLOYEE_ID LAST_NAME MANAGER_ID LEVEL 101 Kochhar 100 1 108 Greenberg 101 2 109 Faviet 108 3 110 Chen 108 3 111 Sciarra 108 3 112 Urman 108 3 113 Popp 108 3 START WITH Examples The next example adds a START WITH clause to specify a root row for the hierarchy and an ORDER BY clause using the SIBLINGS keyword to preserve ordering within the hierarchy SELECT last_name employee_id manager_id LEVEL FROM employees START WITH employee_id 100 CONNECT BY PRIOR employee_id manager_id ORDER SIBLINGS BY last_name LAST_NAME EMPLOYEE_ID MANAGER_ID LEVEL King 100 1 Cambrault 148 100 2 Bates 172 148 3 Bloom 169 148 3 Fox 170 148 3 Kumar 173 148 3 Ozer 168 148 3 Smith 171 148 3 De Haan 102 100 2 Hunold 103 102 3 Austin 105 103 4 Ernst 104 103 4 Lorentz 107 103 4 Pataballa 106 103 4 Errazuriz 147 100 2 Ande 166 147 3 Banda 167 147 3 In the hremployees table the employee Steven King is the head of the company and has no manager Among his employees is John Russell who is the manager of department 80 If we update the employees table to set Russell as Kings manager we will create a loop in the data UPDATE employees SET manager_id 145 WHERE employee_id 100 SELECT last_name Employee LEVEL SYS_CONNECT_BY_PATHlast_name Path FROM employees WHERE level 3 AND department_id 80 START WITH last_name King CONNECT BY PRIOR employee_id manager_id AND LEVEL 4 2 3 4 5 6 7 ERROR ORA01436 CONNECT BY loop in user data The NOCYCLE parameter in the CONNECT BY condition causes Oracle to return the rows in spite of the loop The CONNECT_BY_ISCYCLE pseudocolumn shows you which rows contain the cycle SELECT last_name Employee CONNECT_BY_ISCYCLE Cycle LEVEL SYS_CONNECT_BY_PATHlast_name Path FROM employees WHERE level 3 AND department_id 80 START WITH last_name King CONNECT BY NOCYCLE PRIOR employee_id manager_id AND LEVEL 4 Employee Cycle LEVEL Path Russell 1 2 KingRussell Tucker 0 3 KingRussellTucker Bernstein 0 3 KingRussellBernstein Hall 0 3 KingRussellHall Olsen 0 3 KingRussellOlsen Cambrault 0 3 KingRussellCambrault Tuvault 0 3 KingRussellTuvault Partners 0 2 KingPartners King 0 3 KingPartnersKing Sully 0 3 KingPartnersSully McEwen 0 3 KingPartnersMcEwen CONNECT_BY_ROOT Examples The following example returns the last name of each employee in department 110 each manager above that employee in the hierarchy the number of levels between manager and employee and the path between the two SELECT last_name Employee CONNECT_BY_ROOT last_name Manager LEVEL1 Pathlen SYS_CONNECT_BY_PATHlast_name Path FROM employees WHERE LEVEL 1 and department_id 110 CONNECT BY PRIOR employee_id manager_id Employee Manager Pathlen Path Higgins Kochhar 1 KochharHiggins Gietz Kochhar 2 KochharHigginsGietz Gietz Higgins 1 HigginsGietz Higgins King 2 KingKochharHiggins Gietz King 3 KingKochharHigginsGietz The following example uses a GROUP BY clause to return the total salary of each employee in department 110 and all employees below that employee in the hierarchy SELECT name SUMsalary Total_Salary FROM SELECT CONNECT_BY_ROOT last_name as name Salary FROM employees WHERE department_id 110 CONNECT BY PRIOR employee_id manager_id GROUP BY name NAME Total_Salary Gietz 8300 Higgins 20300 King 20300 Kochhar 20300 See Also LEVEL Pseudocolumn and CONNECT_BY_ISCYCLE Pseudocolumn for a discussion of how these pseudocolumns operate in a hierarchical query SYS_CONNECT_BY_PATH for information on retrieving the path of column values from root to node order_by_clause for more information on the SIBLINGS keyword of ORDER BY clauses Page 315 of 479

B I O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O B O O O B O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O


Home Page JDBCTM Database Access JDBC Basics Previous Trail The Java Tutorials have been written for JDK 8 Examples and practices described in this page dont take advantage of improvements introduced in later releases Using Structured Objects MySQL and Java DB currently do not support userdefined types Consequently no JDBC tutorial example is available to demonstrate the features described in this section The following topics are covered Overview of Structured Types Using DISTINCT Type in Structured Types Using References to Structured Types Sample Code for Creating SQL REF Object Using UserDefined Types as Column Values Inserting UserDefined Types into Tables Overview of Structured Types SQL structured types and DISTINCT types are the two data types that a user can define in SQL They are often referred to as UDTs userdefined types and you create them with a SQL CREATE TYPE statement Getting back to the example of The Coffee Break suppose that the owner has been successful beyond all expectations and has been expanding with new branches The owner has decided to add a STORES table to the database containing information about each establishment STORES will have four columns STORE_NO for each stores identification number LOCATION for its address COF_TYPES for the coffees it sells MGR for the name of the store manager The owner makes the column LOCATION be a SQL structured type the column COF_TYPES a SQL ARRAY and the column MGR a REFMANAGER with MANAGER being a SQL structured type The first thing the owner must define the new structured types for the address and the manager A SQL structured type is similar to structured types in the Java programming language in that it has members called attributes that may be any data type The owner writes the following SQL statement to create the new data type ADDRESS CREATE TYPE ADDRESS NUM INTEGER STREET VARCHAR40 CITY VARCHAR40 STATE CHAR2 ZIP CHAR5 In this statement the new type ADDRESS has five attributes which are analogous to fields in a Java class The attribute NUM is an INTEGER the attribute STREET is a VARCHAR40 the attribute CITY is a VARCHAR40 the attribute STATE is a CHAR2 and the attribute ZIP is a CHAR5 The following excerpt in which con is a valid Connection object sends the definition of ADDRESS to the database String createAddress CREATE TYPE ADDRESS NUM INTEGER STREET VARCHAR40 CITY VARCHAR40 STATE CHAR2 ZIP CHAR5 Statement stmt concreateStatement stmtexecuteUpdatecreateAddress Now the ADDRESS structured type is registered with the database as a data type and the owner can use it as the data type for a table column or an attribute of a structured type Using DISTINCT Type in Structured Type One of the attributes the owner of The Coffee Break plans to include in the new structured type MANAGER is the managers telephone number Because the owner will always list the telephone number as a 10digit number to be sure it includes the area code and will never manipulate it as a number the owner decides to define a new type called PHONE_NO that consists of 10 characters The SQL definition of this data type which can be thought of as a structured type with only one attribute looks like this CREATE TYPE PHONE_NO AS CHAR10 Or as noted earlier for some drivers the definition might look like this CREATE DISTINCT TYPE PHONE_NO AS CHAR10 A DISTINCT type is always based on another data type which must be a predefined type In other words a DISTINCT type can not be based on a userdefined type UDT To retrieve or set a value that is a DISTINCT type use the appropriate method for the underlying type the type on which it is based For example to retrieve an instance of PHONE_NO which is based on a CHAR type you would use the method getString because that is the method for retrieving a CHAR Assuming that a value of type PHONE_NO is in the fourth column of the current row of the ResultSet object rs the following line of code retrieves it String phoneNumber rsgetString4 Similarly the following line of code sets an input parameter that has type PHONE_NO for a prepared statement being sent to the database pstmtsetString1 phoneNumber Adding on to the previous code fragment the definition of PHONE_NO will be sent to the database with the following line of code stmtexecuteUpdate CREATE TYPE PHONE_NO AS CHAR10 After registering the type PHONE_NO with the database the owner can use it as a column type in a table or as the data type for an attribute in a structured type The definition of MANAGER in the following SQL statement uses PHONE_NO as the data type for the attribute PHONE CREATE TYPE MANAGER MGR_ID INTEGER LAST_NAME VARCHAR40 FIRST_NAME VARCHAR40 PHONE PHONE_NO Reusing stmt defined previously the following code fragment sends the definition of the structured type MANAGER to the database String createManager CREATE TYPE MANAGER MGR_ID INTEGER LAST_NAME VARCHAR40 FIRST_NAME VARCHAR40 PHONE PHONE_NO stmtexecuteUpdatecreateManager Using References to Structured Types The owner of The Coffee Break has created three new data types used as column types or attribute types in the database The structured types LOCATION and MANAGER and the DISTINCT type PHONE_NO The entrepreneur has used PHONE_NO as the type for the attribute PHONE in the new type MANAGER and ADDRESS as the data type for the column LOCATION in the table STORES The MANAGER type could be used as the type for the column MGR but instead the entrepreneur prefers to use the type REFMANAGER because the entrepreneur often has one person manage two or three stores Using REFMANAGER as a column type avoids repeating all the data for MANAGER when one person manages more than one store With the structured type MANAGER already created the owner can now create a table containing instances of MANAGER that can be referenced A reference to an instance of MANAGER will have the type REFMANAGER A SQL REF is nothing more than a logical pointer to a structured type so an instance of REFMANAGER serves as a logical pointer to an instance of MANAGER Because a SQL REF value needs to be permanently associated with the instance of the structured type that it references it is stored in a special table together with its associated instance A programmer does not create REF types directly but rather creates the table that will store instances of a particular structured type that can be referenced Every structured type that is to be referenced will have its own table When you insert an instance of the structured type into the table the database automatically creates a REF instance For example to contain instances of MANAGER that can be referenced the owner created the following special table using SQL CREATE TABLE MANAGERS OF MANAGER OID REFMANAGER VALUES ARE SYSTEM GENERATED This statement creates a table with the special column OID which stores values of type REFMANAGER Each time an instance of MANAGER is inserted into the table the database will generate an instance of REFMANAGER and store it in the column OID Implicitly an additional column stores each attribute of MANAGER that has been inserted into the table as well For example the following code fragment shows how the entrepreneur created three instances of the MANAGER structured type to represent three managers INSERT INTO MANAGERS MGR_ID LAST_NAME FIRST_NAME PHONE VALUES 000001 MONTOYA ALFREDO 8317225600 INSERT INTO MANAGERS MGR_ID LAST_NAME FIRST_NAME PHONE VALUES 000002 HASKINS MARGARET 4084355600 INSERT INTO MANAGERS MGR_ID LAST_NAME FIRST_NAME PHONE VALUES 000003 CHEN HELEN 4153785600 The table MANAGERS will now have three rows one row for each manager inserted so far The column OID will contain three unique object identifiers of type REFMANAGER one for each instance of MANAGER These object identifiers were generated automatically by the database and will be permanently stored in the table MANAGERS Implicitly an additional column stores each attribute of MANAGER For example in the table MANAGERS one row contains a REFMANAGER that references Alfredo Montoya another row contains a REFMANAGER that references Margaret Haskins and a third row contains a REFMANAGER that references Helen Chen To access a REFMANAGER instance you select it from its table For example the owner retrieved the reference to Alfredo Montoya whose ID number is 000001 with the following code fragment String selectMgr SELECT OID FROM MANAGERS WHERE MGR_ID 000001 ResultSet rs stmtexecuteQueryselectMgr rsnext Ref manager rsgetRefOID Now the variable manager can be used as a column value that references Alfredo Montoya Sample Code for Creating SQL REF Object The following code example creates the table MANAGERS a table of instances of the structured type MANAGER that can be referenced and inserts three instances of MANAGER into the table The column OID in this table will store instances of REFMANAGER After this code is executed the MANAGERS table will have a row for each of the three MANAGER objects inserted and the value in the OID column will be the REFMANAGER type that identifies the instance of MANAGER stored in that row Using UserDefined Types as Column Values Our entrepreneur now has the UDTs required to create the table STORES The structured type ADDRESS is the type for the column LOCATION and the type REFMANAGER is the type for the column MGR The UDT COF_TYPES is based on the SQL data type ARRAY and is the type for the column COF_TYPES The following line of code creates the type COF_ARRAY as an ARRAY value with 10 elements The base type of COF_ARRAY is VARCHAR40 CREATE TYPE COF_ARRAY AS ARRAY10 OF VARCHAR40 With the new data types defined the following SQL statement creates the table STORES CREATE TABLE STORES STORE_NO INTEGER LOCATION ADDRESS COF_TYPES COF_ARRAY MGR REFMANAGER Inserting UserDefined Types into Tables The following code fragment inserts one row into the STORES table supplying values for the columns STORE_NO LOCATION COF_TYPES and MGR in that order INSERT INTO STORES VALUES 100001 ADDRESS888 Main_Street Rancho_Alegre CA 94049 COF_ARRAYColombian French_Roast Espresso Colombian_Decaf French_Roast_Decaf SELECT OID FROM MANAGERS WHERE MGR_ID 000001 The following goes through each column and the value inserted into it STORE_NO 100001 This column is type INTEGER and the number 100001 is an INTEGER type similar to entries made before in the tables COFFEES and SUPPLIERS LOCATION ADDRESS888 Main_Street Rancho_Alegre CA 94049 The type for this column is the structured type ADDRESS and this value is the constructor for an instance of ADDRESS When we sent the definition of ADDRESS was sent to the database one of the things it did was to create a constructor for the new type The commaseparated values in parentheses are the initialization values for the attributes of the ADDRESS type and they must appear in the same order in which the attributes were listed in the definition of the ADDRESS type 888 is the value for the attribute NUM which is an INTEGER value Main_Street is the value for STREET and Rancho_Alegre is the value for CITY with both attributes being of type VARCHAR40 The value for the attribute STATE is CA which is of type CHAR2 and the value for the attribute ZIP is 94049 which is of type CHAR5 COF_TYPES COF_ARRAY Colombian French_Roast Espresso Colombian_Decaf French_Roast_Decaf The column COF_TYPES is of type COF_ARRAY with a base type of VARCHAR40 and the commaseparated values between parentheses are the String objects that are the array elements The owner defined the type COF_ARRAY as having a maximum of 10 elements This array has 5 elements because the entrepreneur supplied only 5 String objects for it MGR SELECT OID FROM MANAGERS WHERE MGR_ID 000001 The column MGR is type REFMANAGER which means that a value in this column must be a reference to the structured type MANAGER All of the instances of MANAGER are stored in the table MANAGERS All of the instances of REFMANAGER are also stored in this table in the column OID The manager for the store described in this table row is Alfredo Montoya and his information is stored in the instance of MANAGER that has 100001 for the attribute MGR_ID To get the REFMANAGER instance associated with the MANAGER object for Alfredo Montoya select the column OID that is in the row where MGR_ID is 100001 in the table MANAGERS The value that will be stored in the MGR column of the STORES table the REFMANAGER value is the value the DBMS generated to uniquely identify this instance of the MANAGER structured type Send the preceding SQL statement to the database with the following code fragment String insertMgr INSERT INTO STORES VALUES 100001 ADDRESS888 Main_Street Rancho_Alegre CA 94049 COF_ARRAYColombian French_Roast Espresso Colombian_Decaf French_Roast_Decaf SELECT OID FROM MANAGERS WHERE MGR_ID 000001 stmtexecuteUpdateinsertMgr However because you are going to send several INSERT INTO statements it will be more efficient to send them all together as a batch update as in the following code example

O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O B O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O B I O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O B O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O