IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Detail example with explaination for ALTER command


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Bharani

New User


Joined: 02 Jul 2004
Posts: 4

PostPosted: Fri Jul 02, 2004 3:25 pm
Reply with quote

Hai Friends,

I am having doubt in db2 alter command.

can anyone give detail example with explaination for alter command.

that is alter table, alter column, alter constraints, drop constaints, drop column
Back to top
View user's profile Send private message
priya

Moderator


Joined: 24 Jul 2003
Posts: 568
Location: Bangalore

PostPosted: Sat Jul 03, 2004 12:21 am
Reply with quote

ALTER command is used to alter the parameters of STORAGE GROUP or TABLE, index and tablespace.
Back to top
View user's profile Send private message
krbabu

New User


Joined: 20 Feb 2004
Posts: 57

PostPosted: Mon Jul 05, 2004 1:07 pm
Reply with quote

Hi barani,
Alter command is used to alter the structure of the table, length of the colums and change the constraint.
Back to top
View user's profile Send private message
Bharani

New User


Joined: 02 Jul 2004
Posts: 4

PostPosted: Tue Jul 06, 2004 9:22 am
Reply with quote

Hai Friends

I need example query. please explain with example query for alter
Back to top
View user's profile Send private message
meetsrk

New User


Joined: 13 Jun 2004
Posts: 85

PostPosted: Tue Jul 06, 2004 9:35 pm
Reply with quote

hi bharani,

while using alter table in DB2 always keep these things in mind,

u cannot do the following,

#change not null --> null
#reduce the size of the field i.e char(20) to Char(10)
#drop a praticular column

a syntax to add a new column for size 10 fields.

Code:

alter table existing-table-name add new-column-name char(10)
Back to top
View user's profile Send private message
Bharani

New User


Joined: 02 Jul 2004
Posts: 4

PostPosted: Wed Jul 07, 2004 9:32 am
Reply with quote

[quote] Thank U Friend if u r giving more examples means i will be comfortable. then can we create sequence in db2 if we can means what is the syntax to create the sequence.
Quote:
Back to top
View user's profile Send private message
satya123
Warnings : 1

New User


Joined: 18 Aug 2006
Posts: 57

PostPosted: Sat Aug 19, 2006 12:50 pm
Reply with quote

u can increase the column size for varchar fields but not decrease
Back to top
View user's profile Send private message
mahsug

New User


Joined: 01 Jul 2003
Posts: 15
Location: Phoenix , AZ

PostPosted: Mon Aug 21, 2006 11:59 am
Reply with quote

Hi Bharani ,

Yes, you can create Sequences in Db2 , Below are the informations regarding the same .

To Create a Sequence

You need to have any one of the following :

| The CREATEIN privilege on the schema

| SYSADM or SYSCTRL authority

Command :

CREATE SEQUENCE ORDER_SEQ
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO CYCLE
CACHE 20;

Note :
1) You need to provide the starting value , and incrementing value , say here it is 1 , so every time you say next value , it will be incremented by 1
2) MAXVALUE : MaxVALUE is the maximum value for your sequence , if you say 25 , your sequence will range from 1 - 25
3) CYCLE : When your maxvalue is reached , this is to say whether you want to reuse the same sequence numbers , say if you say MAXVALUE is 10 and CYCLE YES , when your sequence reaches 10 and you call for the next value , the sequence will be resetted to the first value , ie 1 .

Using Sequence values with your DML Operations

INSERT INTO ORDERS (ORDERNO, CUSTNO)
VALUES (NEXT VALUE FOR ORDER_SEQ, 123456);

UPDATE ORDERS
SET ORDERNO = NEXT VALUE FOR ORDER_SEQ
WHERE ORDERNO = 123456;


Hope , I have cleared your doubt .

Bye ,
Mahesh
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts RACF - Rebuild SETROPTS command which... All Other Mainframe Topics 3
No new posts Routing command Address SDSF to other... TSO/ISPF 2
No new posts DTL - how to define key with stacked ... TSO/ISPF 3
No new posts LTJ command CA Products 4
No new posts DROP & ALTER PARTITION-PBR DB2 0
Search our Forums:

Back to Top