Click to See Complete Forum and Search --> : How to add new column to an existing table


yoyali
09-02-2006, 03:11 AM
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 :)

Ribeyed
09-02-2006, 05:27 AM
Hi,

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

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

hope this helps

yoyali
09-02-2006, 05:32 AM
yah it helped alot
thanx :)

russell_g_1
09-02-2006, 05:34 AM
you're letting your users alter the structure of your database?

Ribeyed
09-02-2006, 05:41 AM
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.

yoyali
09-02-2006, 05:42 AM
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

russell_g_1
09-02-2006, 06:14 AM
you need something like this

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.