Insert into | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Insert into

I have a tablw with about 10000 records in it and I’m looking to add a new column to the table. The value for this column will be the same for every record is it possible to write an insert statement that will insertthe value for every record. I have tried the following INSERT INTO ST.db:confused:rderTable (Man_site)
VALUES (‘Pes’) But once i run the query I want it to insert the value for every record in the table. Is this possible???? Cheers
alter the table to add the new column with default value which you want it to be for all rows. After column addition
fire UPDATE query instead of INSERT to update that column with value you have specified as default.

Learn SQL http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp Madhivanan Failing to plan is Planning to fail
You might also want to create a DEFAULT constraint on that column, so that the specific value automatically is inserted unless you explicitly supply some other value. So, something like this:
ALTER TABLE db:confused:rderTable
ADD CONSTRAINT DF_Man_Site DEFAULT (‘Pes’) FOR Man_Site

Frank Kalis
Moderator
Microsoft SQL Server MVP
Webmaster:http://www.insidesql.de
Note that a default constraint does not overrule a NULL that is inserted. The default value is inserted when the column is not mentioned in the column list – say you have a table Target with columns A and B, and there is a default constraint on B (‘Pes’): INSERT INTO target (A, B) SELECT ‘a’, null
INSERT INTO target (A) SELECT ‘b’ Note that only the second row will have ‘Pes’ on column B.
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by SquirrelJ</i><br /><br />I have a tablw with about 10000 records in it and I’m looking to add a new column to the table. The value for this column will be the same for every record <hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote"><br />If the value of a column is same for every record in a table, then that column does not belongs to that table [<img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />]<br /><br />Roji. P. Thomas<br /<a target="_blank" href=http://toponewithties.blogspot.com>http://toponewithties.blogspot.com</a><br />
]]>