Change Column Data In All Tables At Once

Sep 17, 2005

I would like to change column data in all tables in a single database at once.

For instance, i have many tables in a database, and about 30% of the tables has the column "orderplace".
And all the data in orderplace (every tables in the database) are "houston". instead of going to each table and
"update table set orderplace = 'dallas' " .... is there anyway that i could run a sql statement and it will update all the tables in database that has the orderplace column to "orderplace = 'dallas' " ?

any ideas ? thanks.

View 5 Replies


ADVERTISEMENT

How To Change Column Order In Tables?

Apr 14, 2008

I'm using VBE 2008 and in the edit table schema box it doesn't allow reordering the columns. Any solutions?

View 1 Replies View Related

DB Design :: Change Order Of Column In Database Tables

Jul 22, 2015

How to Change Order of Column In Database Tables

View 10 Replies View Related

Transact SQL :: Find Unmatching Columns Between Two Tables While Applying A Change Column Prefix Table

Nov 16, 2015

For our ETL process, we maintain a TransformationList table that has the source view and the destination table. Data is copied from the view into the table (INSERT INTO). I am trying to find column names in the Views that are not column names in the associated Table.

In the below example, want to end up with three records:

 1, View1, Column4
 2, View2, Column4
 2, View2, Column5

I have it almost working, except that there is a table, ChangeColPrefix table, that is used by the ETL process to change some of the view's column name prefixes. Some of the source views have column names with prefixes that do not match the destination table column names. Say view SouthBase has all the column names prefixed with SB - like SBAcct, SBName. And the Destination table of Area District has ADAcct, ADName. There would be a row in the ChangeColPrefix for SouthBase, SB, AD, 1, 2 that would be used by the ETL process to create the INSERT INTO Area District From SouthBase.

I need to use this ChangeColPreifx to find my unmatching columns between my source views and destination tables. With out that table SBAcct and SBName from SouthBase will not appear to match the columns of ADAcct and ADName, but they do match.

I want to end up with these three records as non-matching:

View1, Column4
View2, Column4
View2, Column5

View1 has Salumn2 and View2 has Salumn5, and they must be changed to Column2 and Column5 as per the ChangeColPrefix table before running the Select from INFORMATION_SCHEMA.COLUMNS EXCEPT Select from INFORMATION_SCHEMA.COLUMNS looking for unmatched columns.

/***** Set Up Test Data *****/
-- Create 2 test views
IF EXISTS(SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[View1]'))
DROP VIEW dbo.[View1]
GO
CREATE VIEW View1
AS SELECT '1' AS Column1 , '2' AS Salumn2 , '4' AS Column4;

[Code] ....

View 3 Replies View Related

Change Data Type In Many Tables In One Go

May 14, 2008



Hi.

I have tables (they are empty and there are no constraints) with columns typed as varchar. In a database I want to change the type of all the varchar columns in all the tables from varchar to nvarchar. What's the best way to do it? Can you suggest code?

I know that to get all the relevant columns I would issue a query like this

select *
from information_schema.columns
where data_type = 'varchar'

Then I would use a cursor... And that's exactly what I would not like to do. Is there any other way?

Thanx.
Darek

View 3 Replies View Related

How To Change Column Data As Row

Oct 28, 2007

hi

I have a table like this




Username

Clicks

Impressions

Download


User1

12

23

43


User2

34

33

59


User3

39

88

77


User4

34

43

43
need to change the table like this







User1

User2

User3

User4


clicks

12

42

43

43


Impressions

43

43

43

43


download

43

43

43

43
Thanks
Ezhil

View 4 Replies View Related

Modifying Change Data Capture Tables?

Oct 29, 2015

We have enabled Change Data Capture for auditing our table changes in SQL Server 2008. There is a request to NULL out a few columns (for all rows) in a couple CDC tables, due to compliance with a certification. Is there a compelling reason not to modify these tables and to leave the audit trail as-is?

View 1 Replies View Related

SQL Change Column Data Type

Aug 20, 2007

How do I programatically  change a column (say username) in a table (say tblusers) from varchar(25) to varchar(100)I am looking for something likealter tblusers set username as  varchar(100) I know the above statement in nonsensical but it conveys the idea. 

View 3 Replies View Related

Change Data In Column Of Table

Feb 24, 2014

How to modify/change data that is in a SQL table column. Here is what I need or have

I have 2 tables, Table 1 and Table 2, within those 2 tables there is 1 Column that has the same column heading aswell as data within,(I will call it the serial_number column) there is also a 2nd column that is labeled the Same in both tables, I would like to be able to update the Values in the 2nd column of table 1 with the values from table 2 column 3, using the Serial_number column as my matching reference between the 2, the data is not in the same order between the 2 Tables,

More or less I need to set the value of table 1/column 2 to match table 2/column 3, where the serial_numbers are the same in both tables serial_number columns, the data being changed is set as Small int...

View 3 Replies View Related

Sql Script To Change Type Of Column With Data

Sep 29, 2007

I have a table say Friend which has a column "IsSingle VARCHAR(10)" and this column has values like yes or No
Now I want to change type of column IsSingle from VARCHAR to BIT, if I try to do it manaually SQL throws error that cannot convert yes to bit etc.
I know that we can write a script to do this task but i dont know how ?
Any pointers,links, suggestions will help me to start with.
 
Thanks for your help. 
 
 

View 2 Replies View Related

Change Value Of Column Mimetype In Table Data

Aug 23, 2013

I have two tables:

dtr
dataid........Subtype
data
docid....mimetype

I need to change the value of column mimetype in table data, but only for these entries which have the value 144 in column "Subtype" in table dtr.

Here is my sql:

with cte as (
select
DataID,
SubType,
MimeType
from dtr A1, data A2
where A1.dataid=A2.Docid And A1.Subtype='144'
AND
A2.mimetype='application/news-message-id'
)
update cte set MimeType = 'application/x-outlook-msg'

I've tested it and it works. Do you see any problems with this SQL?

As updates are risky I'll do a database backup. Is it possible to get all changed entries so that I can track my update, because I don't have a report about the changes? Maybe that everythin is transferred to an output file?

View 4 Replies View Related

Change Duplicate Data In Server Column

Oct 17, 2014

I want to change duplicate data in my sql server column.

the data= 'Barack Obama' , what I want
'Barack Obama 23453'

I have the following query:

UPDATE klant SET naamvoornaam=naamvoornaam + CAST(klantnummer AS VARCHAR)
WHERE naamvoornaam NOT IN (
SELECT(naamvoornaam)
FROM klant
GROUP BY naamvoornaam
HAVING ( COUNT(naamvoornaam) = 1 ))

Message from messages:
String or binary data would be truncated.

I think the max length exceeds the length of the destination column. I've tried:

Max(Len(naamvoornaam + CAST(klantnummer AS VARCHAR)))

message from messages:
An aggregate may not appear in the set list of an UPDATE statement.

View 7 Replies View Related

What Is The Best Practice To Change A Column's Data Type In A Very Big Table?

Dec 11, 2007



Hi All,

I am using SQL Server 2000 Enterprise Edition fully patched. Database is in Simple Recovery mode.

I need to change a column's data type from "int(4)" to "smallint(2)". I know for sure that there will be no data (precision) lost, because I know the possible values that this column could have.

My problem is that the table I am dealing with has 600,000,000 records in it. I dropped all indexes before I tried to alter the table. But still it is taking forever and filling up my 280GB disk with transaction log file.

I know that in Oracle, if I want I can turn off logging and do these kind of modifications relatively faster.

I was wondering if there is a way of disabling logging before running this alter command.

What is the best practice to handle a situation of this sort?

I appreciate your help.

Thanks in advance,
Sinan Topuz

View 3 Replies View Related

Update On Large Table - Change Data Type For Text Column

Dec 10, 2014

I need to update a large table, about 55 million rows, without filling the transaction log, in the shortest time as possible. The goal is to alter the table and change the data type for Text column from VARCHAR(7900) to NVARCHAR(MAX).

Since I cannot do it with an ALTER TABLE statement (it would fill up the transaction log) I'm thinking to:

- rename column Text in Text_OLD
- add Text column of type NVARCHAR(MAX)
- copy values in batches from Text_OLD to Text

The table is defined like:

create table DATATEXT(
rID INTEGER NOT NULL,
sID INTEGER NOT NULL,
pID INTEGER NOT NULL,
cID INTEGER NOT NULL,
err TINYINT NOT NULL,

[Code] ....

I've thought about a stored procedure doing this but how to copy values in batch from Text_OLD to Text.

The code I would start with (doing just this part) is the following, but maybe there are more efficient ways to do it, or at least there's a better way to select @startSeq in the WHILE loop (avoiding to select a bunch of 100000 sequences and later selecting the max).

declare @startSeq timestamp
declare @lastSeq timestamp
select @lastSeq = MAX(sequence) from [DATATEXT] where [Text] is null
select @startSeq = MIN(Sequence) FROM [DATATEXT] where [Text]is null
BEGIN TRANSACTION T1
WHILE @startSeq < @lastSeq

[Code] ....

View 1 Replies View Related

To Get A Column Data Which Spanned Multiple Tables

Jun 12, 2008

All,
i am looking for a query which fetches data from column 'managerid' which spread across 20 tables,

Managerid colums is spread across 20 tables and i need only managerid data from all the tables available, data for managerid column will be different in each table.

can anyone help me regarding the same.

View 2 Replies View Related

Join Tables With Almost Identical Column Data

Oct 29, 2014

Selecting the data from these two tables? The columns 'host_ext_id' have the same data BUT in 'adrmst' all data is preceeded by A0000.

table is 'adrmst'

Host External IDAddress NameAddress Line 1Address Line 2City StatePostal Code
A000042401 T-3803VC 1530401 00 WENGER STTOPEKA KS66609
A000042402 CO INC 960 PP TOMLIN MILL RDSTATESVILLENC286258332
A000042403 CO INC 1420 PP BLVD GARYSBURGNC278319748
A000042405 CO INC 1419 PP BROWN RD KISSIMMEEFL347463415
A000042405 CO INC 962 PP COMMERCE DRVALDOSTAGA316011206

table is 'shipment'

Shipment IDHost External IDcar_move_idP_DEST_LOC_ID
42401 42401
42402 42402 SDQD_00862TAGSDQD
42403 42403 SDQD_00863TAGSDQD
42404 42404 SDQD_00863TAGSDQD
42405 42405 SDQD_00863TAGSDQD

View 4 Replies View Related

Replicating Data To Tables Of Different Column Names

Apr 17, 2007

hi,

is it possible to replicate data from one table to another which have different names,different schemas and different column names.



Im trying this using transactional replication.

i achieved this for different schema, different table names.but it is failing for different column names.



till now i haven't got a proper reply for my problem.









regards

Baji Prasad.B

View 5 Replies View Related

How To Find Differences In Column Data Types Between Tables In Two Different Databases Using TSQL

Apr 21, 2008


I have Two Database that exist on Two seperate servers. The two database contain same schema and contains tables and columns of same name. Some tables have slight differences in terms of data types or Data type lenght.

For example if a Table on ServerA has a column named - CustomerSale with Varchar (100, Null) and a table on ServerB has a column named CustomerSale with Varchar (60, Null), how can i find if other columns have similar differences in all tables with the same name and columns in the two servers.

I am using SQL Server 2005. And the Two Servers are Linked Servers

What Script can i use to accomplish this task. Thanks






View 4 Replies View Related

Reseeding Temporary Tables Or Table Data Types With Identity Column

Feb 17, 2006

Hi,

I have a indexing problem. I have a sequence that needs to has a index number. I want to use a table data type and have a working sample BUT I cannot reseed the table when needed. How do I do this.

This works only for the first ExitCoilID then I need to RESEED.



Here is my code:



DECLARE

@EntryCoilCnt AS INT,

@ExitCoilID AS INT,

@SubtractedFromEntyCoilCnt AS INT

DECLARE

@ExitCoilID_NotProcessed TABLE

(ExitCoilID int)



INSERT INTO @ExitCoilID_NotProcessed

SELECT DISTINCT ExitCoilID

FROM

dbo.TrendEXIT

where

ExitCoilID is not null and

ExitCnt is null

order by

ExitCoilID



DECLARE

@ExitCoilID_Cnt_Index TABLE

(ExitCoilID int, ExitCnt int IDENTITY (1,1))

IF @@ROWCOUNT > 0

BEGIN

DECLARE ExitCoilID_cursor CURSOR FOR

SELECT ExitCoilID FROM @ExitCoilID_NotProcessed

ORDER BY ExitCoilID

OPEN ExitCoilID_cursor

FETCH NEXT FROM ExitCoilID_cursor

INTO @ExitCoilID

WHILE @@FETCH_STATUS = 0

BEGIN

INSERT INTO @ExitCoilID_Cnt_Index

SELECT ExitCoilID

FROM dbo.TrendEXIT

WHERE

ExitCoilID = @ExitCoilID

ORDER BY

EntryCoilID, Cnt

select * from @ExitCoilID_Cnt_Index

--truncate @ExitCoilID_Cnt_Index

--DBCC CHECKIDENT ('@ExitCoilID_Cnt_Index', RESEED, 1)

FETCH NEXT FROM ExitCoilID_cursor

INTO @ExitCoilID

END

CLOSE ExitCoilID_cursor

DEALLOCATE ExitCoilID_cursor

select * from @ExitCoilID_Cnt_Index

END --IF @@ROWCOUNT <> 0

View 8 Replies View Related

Reporting Services :: Change Column Size Dynamically Depends On Content Of The Column?

Jun 4, 2015

How to change column size dynamically depends on content of the column.

View 2 Replies View Related

Change An Int Column To Identity Column

Dec 17, 2001

Hi, I want to change an int column (not null) to identity column. I tried
the following:

alter table myTable alter column ID int identity(10, 1) not null

But it failed with the error message:

Incorrect syntax near the keyword 'identity'.

Can someone please show me the correct statement (if it exists)>

Many thanks.

View 4 Replies View Related

Data Warehousing :: Copy Data From Staging Tables To Other Instance Master Tables?

Aug 14, 2015

I need to copy data from warehouse tables to master tables of different SQL instances. Refresh need to done once in an hour. What is the best way to do this? SQL agent jobs or SSIS packages?

View 3 Replies View Related

How To Change Owner For Many Tables

Jun 17, 2004

sorry to be dumb!

i have a whole bunch of tables with me as owner - i want to make dbo owner.

how?

i just can't find an appropriate mouse click in enterprise manager, and i don't really want the 40 command lines to do it manually.

thanks for ideas, izy

View 6 Replies View Related

Change Collation For All Tables

Apr 30, 2008

Problem is, the database collation is "SQL_Latin1_General_CP1_CI_AS" and some fields of some tables have the collation "Latin1_General_CI_AS". You know the Problem ... ;-)

As I don't want to change the columns one by one, I want to ask how can I change collation of all column in a table by 1 Transact SQL? Or how can I change the collation of all the tables?

Thanks, ON

View 1 Replies View Related

Cant Change The Tables With The Web Page

May 5, 2008

hello
i"m new to sql , i have sql 2005 express

my problam is that i cant change or add the data in the tables from the web page i built.
INSERT , UPDATE , DELETE they all to nothing

( i can read the data and write it to the web!)

why is that?

thanks

View 2 Replies View Related

Change All Tables Collation At Once..

Apr 24, 2008



Hi,

I'm using SQl Server 2005 and I need to know how can I change all table's column collation to the database default....It's too $%¨& to enter table by table and check if it's with other collate and then change...

Thanks

View 5 Replies View Related

Change Primary Key In One Of Tables

May 26, 2015

I have inherited a SQL Server Database that has three tables related to one another.  The DB uses a Access 2013 front end. I know access fairly well, but am not all that competent when it comes to SQL Server. I am using SQL Server Management Studio 12.  I need to change the primary key in one of the tables.  When I do so, I get the message illustrated below.  How can I get around this?

I did find the place where there is a table option of "Prevent Saving changes that require table re-creation".  However, there seems to be a lot of comments that indicate it should not be turned off.  If I don't turn it off, how can I
make the changes to the table?

View 5 Replies View Related

Change Owner Of All The Tables Of Database

Jun 6, 2008

 
Hi,
 it has to do with my unfamiliarity with creating users and dbo privileges. I'm trying to grant access to an outside vendor to import their latest version of a database. I set them up with a user account that had db_owner privileges, however when they ran the dts process it copied all the data as new tables rather than overwriting the existing tables and the new tables were all associated with the user is created instead of dbo user. What do I need to do to facilitate this process?

View 1 Replies View Related

Change Multiple Tables Owner

Mar 17, 2006

Hi all. I am aware that to change a table's owner i must do:

exec sp_changeobjectowner '[dnnadmin].[aspsearch]' , 'dbo'

However i got about 50 tables in my DB and i'ld like a somehow automated way to change the owner in every table in the DB.

thanks

View 1 Replies View Related

How To Change Owner For All Tables In A Database.

Aug 3, 2006

I am trying to change owner of all tables in a database. How can I doit?

View 1 Replies View Related

How To Change Value In Columns With Same Name In Multiple Tables

May 27, 2008

For a uncomplicated example, our database has 10 tables. Each table contains the column COMPANY. I need to change company from 1 to 4, and I don't want to have to update each table individually (because the number of tables is actually closer to 800).

COMPANY being a primary key isn't an issue.

Is there a painless way to update the COMPANY field in all user defined tables?

View 8 Replies View Related

How To Drop An Identity Column From All Tables Tables In A Database

Mar 2, 2008

Does anyone have a script that can drop the Identity columns from all the tables in a database? Thanks

View 1 Replies View Related

Transact SQL :: SUM Of Two Table Column Base On Another Column Value And SUBTRACT And Join Tables

Oct 14, 2015

I have the following table

Table Name EmployeeInformation
EmployeeID EmployeeFirstName EmployeeLastName
    1             |John                       |Baker
    2             |Carl                        |Lennon
    3             |Marion                    |Herbert

Table Name PeriodInformation
PeriodID PeriodStart PeriodEnd
    1        |1/1/14      |12/30/14
    2        |1/1/15      |12/30/15

[code]...

I want a query to join all this tables based on EmployeeID, PeriodID and LeaveTypeID sum of LeaveEntitlement.LeaveEntitlementDaysNumber based on LeaveTypeID AS EntitleAnnaul and AS EntitleSick and sum AssignedLeave.AssignedLeaveDaysNumber based on LeaveTypeID  AS AssignedAnnaul and AS AssignedSick and subtract EntitleAnnaul from AssignedAnnual based on LeaveTypeID  AS AnnualBalance and subtract EntitleSick from AssignedSick based on LeaveTypeID  AS SickBalance

and the table should be shown as below after executing the query

EmployeeID, EmployeeFirstName, EmployeeLastName, PeriodID, PeriodStart, PeriodEnd, EntitleAnnual, AssignedAnnual, AnnualBalance, EntitleSick, AssignedSick, SickBalance

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved