Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 1st, 2007, 11:49 AM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hassan1365
Default a problem with adding fields in ssems

hi,
i have a DB and it has some tables that the tables has related link (diagram).now when i wanna to change a table's field , the Sql Server errors that the table is not empty.when i try to delete the table's content , Sql server errors that the table is use a relation with another table.
so can i change a table's structure?
by the way before i forget , the Sql Server's error is below:

'UserManagement' table
- Unable to modify table.
ALTER TABLE only allows columns to be added that can contain nulls, or have a DEFAULT definition specified, or the column being added is an identity or timestamp column, or alternatively if none of the previous conditions are satisfied the table must be empty to allow addition of this column. Column 'isadmin' cannot be added to non-empty table 'UserManagement' because it does not satisfy these conditions.


thanks,
M.H.H


M.H.H
Reply With Quote
  #2 (permalink)  
Old June 4th, 2007, 03:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

what is the ALTER TABLE statement that you used? Can you post it here?

_________________________
- Vijay G
Strive for Perfection
Reply With Quote
  #3 (permalink)  
Old June 6th, 2007, 10:57 AM
Authorized User
 
Join Date: Oct 2005
Location: , , .
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Based on the error message that you get, when adding a column in a table that already contains data, you have to either allow NULLs on that column or you have to specify a default value. Here's how your ALTER TABLE will look like, adding isadmin column with a default of 0 (assuming this is a bit column):

ALTER TABLE UserManagement ADD isadmin bit NOT NULL DEFAULT(0)

SQL Server Helper
How well do you know SQL? Find out with the free test assessment from SQL Server Helper!!!
http://www.sql-server-helper.com/free-test/default.aspx

Got a SQL Server Question? Ask us here: http://www.sql-server-helper.com/forums/default.asp
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Time Fields Brendan Bartley Access 3 July 30th, 2006 08:35 PM
Adding dynamic fields ivnavin Crystal Reports 0 December 17th, 2004 03:35 PM



All times are GMT -4. The time now is 04:26 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.