SQL server - adding constraint Chalanachithram.com | Topics | Search
Hide Clipart | Log Out | Register | Edit Profile

Last 30 mins | 1 | 2 | 4 hours     Last 1 | 7 Days

Chalanachithram.com DB » New TF Industry Related » Archive through October 25, 2013 » SQL server - adding constraint « Previous Next »

Author Message
Top of pagePrevious messageNext messageBottom of page Link to this message

Gandhiguevara
Legend
Username: Gandhiguevara

Post Number: 41758
Registered: 10-2009
Posted From: 142.136.137.10

Rating: N/A
Votes: 0 (Vote!)

Posted on Thursday, October 24, 2013 - 08:59 pm:   Insert Quote Edit PostDelete PostPrint Post   Move Post (Moderator/Admin Only)Ban Poster IP (Moderator/Admin only)


Humpty_dumpty:


Top of pagePrevious messageNext messageBottom of page Link to this message

Humpty_dumpty
Moderator
Username: Humpty_dumpty

Post Number: 23682
Registered: 02-2009

Rating: N/A
Votes: 0 (Vote!)

Posted on Thursday, October 24, 2013 - 05:04 pm:   Insert Quote Edit PostDelete PostPrint Post   Move Post (Moderator/Admin Only)Ban Poster IP (Moderator/Admin only)

Ok got it
Thanks ee
Top of pagePrevious messageNext messageBottom of page Link to this message

Casino
Side Hero
Username: Casino

Post Number: 2846
Registered: 01-2012
Posted From: 198.46.98.226

Rating: N/A
Votes: 0 (Vote!)

Posted on Thursday, October 24, 2013 - 05:02 pm:   Insert Quote Edit PostDelete PostPrint Post   Move Post (Moderator/Admin Only)Ban Poster IP (Moderator/Admin only)


Humpty_dumpty:

I know update and add works
Wanted to know if there is a way to combo


alter table is a DDL, not DML. so you can one at a time guru
Top of pagePrevious messageNext messageBottom of page Link to this message

Humpty_dumpty
Moderator
Username: Humpty_dumpty

Post Number: 23681
Registered: 02-2009

Rating: N/A
Votes: 0 (Vote!)

Posted on Thursday, October 24, 2013 - 04:59 pm:   Insert Quote Edit PostDelete PostPrint Post   Move Post (Moderator/Admin Only)Ban Poster IP (Moderator/Admin only)

I know update and add works
Wanted to know if there is a way to combo
Top of pagePrevious messageNext messageBottom of page Link to this message

Casino
Side Hero
Username: Casino

Post Number: 2845
Registered: 01-2012
Posted From: 198.46.98.226

Rating: N/A
Votes: 0 (Vote!)

Posted on Thursday, October 24, 2013 - 04:40 pm:   Insert Quote Edit PostDelete PostPrint Post   Move Post (Moderator/Admin Only)Ban Poster IP (Moderator/Admin only)

ALTER TABLE TTTT ADD CONSTRAINT TTT_test DEFAULT 1 FOR b;
Top of pagePrevious messageNext messageBottom of page Link to this message

Dreamcatcher
Side Hero
Username: Dreamcatcher

Post Number: 4723
Registered: 11-2009
Posted From: 208.86.145.68

Rating: N/A
Votes: 0 (Vote!)

Posted on Thursday, October 24, 2013 - 04:40 pm:   Insert Quote Edit PostDelete PostPrint Post   Move Post (Moderator/Admin Only)Ban Poster IP (Moderator/Admin only)

Idi try seyyi veelaithay....


ALTER TABLE <schema_name,>.<table_name,>
ADD CONSTRAINT df_<column_name,>
DEFAULT <default_expression,>
FOR <column_name,>
GO

If you need to add a foreign key

ALTER TABLE Products WITH CHECK
ADD CONSTRAINT [FK_Prod_Man] FOREIGN KEY(ManufacturerID)
REFERENCES Manufacturers (ID);
Top of pagePrevious messageNext messageBottom of page Link to this message

Casino
Side Hero
Username: Casino

Post Number: 2844
Registered: 01-2012
Posted From: 198.46.98.226

Rating: N/A
Votes: 0 (Vote!)

Posted on Thursday, October 24, 2013 - 04:37 pm:   Insert Quote Edit PostDelete PostPrint Post   Move Post (Moderator/Admin Only)Ban Poster IP (Moderator/Admin only)

update existing rows with default value before altering
Top of pagePrevious messageNext messageBottom of page Link to this message

Buduguuu
Hero
Username: Buduguuu

Post Number: 15781
Registered: 01-2012
Posted From: 192.193.171.158

Rating: N/A
Votes: 0 (Vote!)

Posted on Thursday, October 24, 2013 - 04:37 pm:   Insert Quote Edit PostDelete PostPrint Post   Move Post (Moderator/Admin Only)Ban Poster IP (Moderator/Admin only)

including existing rows enti??

meeru value iyyakapote column lo 1 raavali. ade na mee badha?

adi table level lo column meeda define cheste saripoddi kada?

btw, nenu oracle perspective lo cheppanu. sql server diff aite telvadu naku mari :-)
Different cinema ante Dabangg/GS/CE
Biryani about Mahesh Babu
Top of pagePrevious messageNext messageBottom of page Link to this message

Humpty_dumpty
Moderator
Username: Humpty_dumpty

Post Number: 23680
Registered: 02-2009

Rating: N/A
Votes: 0 (Vote!)

Posted on Thursday, October 24, 2013 - 04:25 pm:   Insert Quote Edit PostDelete PostPrint Post   Move Post (Moderator/Admin Only)Ban Poster IP (Moderator/Admin only)

if pazibul help seyyandi

create table #ttt ( a int, b bit null)

insert into #ttt values (1, null)
insert into #ttt values (2, 1)
insert into #ttt values (3, 0)

select * from #ttt

I want to add a constraint on column b - to have a default value of 1, including existing rows.

ALTER TABLE #ttt ADD CONSTRAINT [DF_b] DEFAULT ((1)) FOR [b] WITH VALUES
DOES NOT work

Add Your Message Here
Post:
Bold text Italics Underline Create a hyperlink Insert a clipart image HASH(0x8e2a2c0){Movie Clipart}
Show / hide regular icons selection options

Click on following links to open cliparts by Alphabetical Order

 A   B   C   D   E   F   G   H   I   J   K   L   M  

 N   O   P   Q   R   S   T   U   V   W   X   Y   Z  

Show / Hide Filmy icons selection options

Click on following links to open cliparts by Alphabetical Order

 A   B   C   D   E   F   G   H   I   J   K   L   M  

 N   O   P   Q   R   S   T   U   V   W   X   Y   Z  

Username: Posting Information:
This is a public posting area. Enter your username and password if you have an account. Otherwise, enter your full name as your username and leave the password blank. Your e-mail address is optional.
Password:
E-mail:
Options: Enable HTML code in message
Automatically activate URLs in message
Action: