Adding a column to a remote DB

R

Rudi Ahlers

How do I add a column in a table on a MSSQL server? I got BuildSQL running,
so I can enter SQL commands to do it, only problem is, I don't know the
command to add a column :)

--

Kind Regards
Rudi Ahlers
+27 (82) 926 1689

Greater love has no one than this, that he lay down his life for his friends
(John 15:13).
 
G

Guest

I don't think you can add a column programmatically. Because you are changing the schema which SQL will not have a clue what to do with the existing data in the database. I am happy to be proven wring though. Also, just out of interest, why would you like to add a column programmatically

You can probably use the DataSet.Merge() Method to Merge a DataTable and its schema into the current DataSet. But that cannot be presist into the DB

Finally, in case you want to create a new table, here is the syntax (quoted from Professional SQL 7 - Wrox

CREATE TABLE [database_name.[owner].]table_nam
({column_name data_typ
[[DEFAULT constant_expression
| [INDENTITY [(seed, increment) [NOT FOR REPLICATION]]]
[ROWGUIDCOL
[NULL|NOT NULL
[<column contraints>
| [column_name AS computed_column_expression
| [<table_constraint>]
[,...n

[ON {<filegroup>|DEFAULT}
[TEXTIMAGE_ON {<filegroup>|DEFAULT}

Example
USE Accountin
CREATE TABLE Employee
(EmployeeID int IDENTITY NOT NULL
FirstName varchar(25) NOT NULL

HT

----- Rudi Ahlers wrote: ----

How do I add a column in a table on a MSSQL server? I got BuildSQL running
so I can enter SQL commands to do it, only problem is, I don't know th
command to add a column :

-

Kind Regard
Rudi Ahler
+27 (82) 926 168

Greater love has no one than this, that he lay down his life for his friend
(John 15:13)
 
R

Rudi Ahlers

Hmm, I don't think I quite understand what you say, since I'm rather new to
this. But, I know in MSSQL Enterprise Manager I can just add the column, and
it works, but now I need to add the same new column, to accept a new field
on my ISP's server, and Enterprise Manager doesn't connect to it.
Thanx for the info from the manual, I don't understand it clearly though

--

Kind Regards
Rudi Ahlers
+27 (82) 926 1689

Greater love has no one than this, that he lay down his life for his friends
(John 15:13).
I don't think you can add a column programmatically. Because you are
changing the schema which SQL will not have a clue what to do with the
existing data in the database. I am happy to be proven wring though. Also,
just out of interest, why would you like to add a column programmatically?

You can probably use the DataSet.Merge() Method to Merge a DataTable and its
schema into the current DataSet. But that cannot be presist into the DB.

Finally, in case you want to create a new table, here is the syntax (quoted
from Professional SQL 7 - Wrox)

CREATE TABLE [database_name.[owner].]table_name
({column_name data_type
[[DEFAULT constant_expression]
| [INDENTITY [(seed, increment) [NOT FOR REPLICATION]]]]
[ROWGUIDCOL]
[NULL|NOT NULL]
[<column contraints>]
| [column_name AS computed_column_expression]
| [<table_constraint>]}
[,...n]
)
[ON {<filegroup>|DEFAULT}]
[TEXTIMAGE_ON {<filegroup>|DEFAULT}]

Example:
USE Accounting
CREATE TABLE Employees
(EmployeeID int IDENTITY NOT NULL,
FirstName varchar(25) NOT NULL)

HTH

----- Rudi Ahlers wrote: -----

How do I add a column in a table on a MSSQL server? I got BuildSQL
running,
so I can enter SQL commands to do it, only problem is, I don't know the
command to add a column :)

--

Kind Regards
Rudi Ahlers
+27 (82) 926 1689

Greater love has no one than this, that he lay down his life for his
friends
(John 15:13).
 
A

Andrew de la Harpe

Rudi you need to consult the BOL that comes with Sql Server.
Look for the ALTER TABLE command.
You might find the microsoft.public.sqlserver.server list more helpful for
these DB specific problems.
A
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top