Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add a new field to database

Status
Not open for further replies.

achai

MIS
May 23, 2000
71
US
how to add a new field to database. i heard use &quot;<b>alter table</b>&quot;. but can anyone give me an example?
 
Here's how to do it in access:<br><br>ALTER TABLE MyTable ADD COLUMN LastName TEXT;<br><br>Here's how to do it with SQL Server:<br><br>ALTER TABLE MyTable ADD COLUMN LastName VARCHAR(30);
 
it looks something is still wrong in &quot;alter table&quot; statement.<br><br>my two files:<br>-------------<br>addcolumn1:<br>&lt;form action=&quot;addcolumn2.cfm&quot; method=&quot;post&quot;&gt;NEW COLUMN: &lt;input type=&quot;text&quot; name=&quot;newcolumn&quot;&gt;&lt;br&gt;<br>&lt;input type=&quot;submit&quot; value=&quot;add it now&quot;&gt;&lt;/form&gt;<br>-------------<br>addcolumn2:<br>&lt;cfquery datasource=&quot;mytable&quot; name=&quot;addcolumn&quot;&gt;<br><b>ALTER TABLE tablename=&quot;Mytable&quot; ADD COLUMN #newcolumn# VARCHAR(30)</b><br>&lt;/cfquery&gt;<br>&lt;cfif #newcolumn#&gt;<br>&lt;cfoutput query=&quot;addcolumn&quot;&gt;<br>&lt;html&gt;&lt;head&gt;&lt;title&gt;add column&lt;/title&gt;&lt;/head&gt;&lt;body&gt;new column #newcolumn# has been added&lt;/body&gt;&lt;/html&gt;<br>&lt;/cfoutput&gt;<br>&lt;cfelse&gt;<br>&lt;cfoutput&gt;can't figure out what you typed in.&lt;/cfoutput&gt;<br>&lt;/cfif&gt;<br>
 
now resolved.<br><br>&lt;cfquery datasource=&quot;mytable&quot;&gt;<br>ALTER TABLE Mytable ADD COLUMN #newcolumn# VARCHAR(30)<br>&lt;/cfquery&gt;<br><br>
 
Whoa, dynamic column names....&nbsp;&nbsp;good luck with that one. :)<br><br>DM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top