www.webdeveloper.com
Results 1 to 7 of 7

Thread: How to add new column to an existing table

  1. #1
    Join Date
    Oct 2005
    Posts
    23

    Question How to add new column to an existing table

    Hi everyone,
    I need help in this matter. I have this form in which the user insert his details, and chose which detail to add and which not and he can add a new field by his own which doesn't exist before. So this new field is a new column, so I just want to know how to add this column into an existing table.
    I'm using sql server 2000
    Many Thanx
    Yoya

  2. #2
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    Hi,

    http://www.w3schools.com/sql/sql_alter.asp

    This shows you how to add a column to an exisiting table

    hope this helps
    ----------------------------------

  3. #3
    Join Date
    Oct 2005
    Posts
    23
    yah it helped alot
    thanx

  4. #4
    Join Date
    Dec 2003
    Location
    England, UK
    Posts
    432
    you're letting your users alter the structure of your database?

  5. #5
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    totally agree with russell. You shouldn't let users alter your database structure. It sounds like your database is not normalized corectly if you are allowing users to add columns. What happens if user1 creates 10 fields that user2 doesn't need but user2 needs 10 other columns and so on till user1000. You'll end up with a lot of columns full of nothing.
    ----------------------------------

  6. #6
    Join Date
    Oct 2005
    Posts
    23
    it's a librarian site there is some configurations which only the librarians know and need for books details and it is updated every now and then so it need to be changed from time to time

  7. #7
    Join Date
    Dec 2003
    Location
    England, UK
    Posts
    432
    you need something like this

    Code:
    create table book
    	(
    	id numeric(18,0) identity(1,1) not null,
    	name nvarchar(100) not null,
    	deleted int not null default(0)
    	)
    
    create table bookfield
    	(
    	id numeric(18,0) identity(1,1) not null,
    	name nvarchar(100) not null,
    	deleted int not null default(0)
    	)
    
    create table linkbookfieldbook
    	(
    	id numeric(18,0) identity(1,1) not null,
    	bookfieldid numeric(18,0) not null,
    	bookid numeric(18,0) not null,
    	value nvarchar(1000) not null,
    	deleted int not null default(0)
    	)
    this would enable the users to add new fields to the books without modifying the db structure. the only downside is that all your fields would be stored as text.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles