Skip to main content

Bulk Update in sql server 2008..

/*Bulk update query*/

create table Table1

(

ID int identity(1,1),

vIsbn varchar(20),

dcPrice decimal(18,2)

)

create table Table2

(

ID int identity(1,1),

vIsbn varchar(20),

dcPrice decimal(18,2)

)

/*Here create two tables, we update Table1's dcPrice column from Table 2 Using Bulk update*/   

insert into Table1(vIsbn,dcPrice)

values('9087657654312',0.00)

insert into Table1(vIsbn,dcPrice)

values('9989876765454',0.00)

insert into Table2(vIsbn,dcPrice)

values('9087657654312',10.20)

insert into Table2(vIsbn,dcPrice)

values('9989876765454',20.10)

select * from Table1

/*here bulk update Query*/

UPDATE Tbl

SET dcPrice=Tbl2.dcPrice

FROM Table1 Tbl

JOIN Table2 AS Tbl2

ON Tbl.vIsbn=Tbl2.vIsbn

select * from Table1

drop table Table1

drop table Table2

Comments

Post a Comment

Popular posts from this blog

Inner join in sql server

INNER JOIN Inner join responsible to returns rows which have a match in both tables. See following example:- CREATE TABLE #ORDER ( orderId INT IDENTITY ( 1 , 1 ), fName VARCHAR ( 400 ), lName VARCHAR ( 400 ), ShipAddress VARCHAR ( 1000 ), dtCreate DATETIME ) CREATE TABLE #ORDER_DETAILS ( orderDetailsId INT IDENTITY ( 1 , 1 ), productName VARCHAR ( 400 ), pPrice DECIMAL ( 18 , 2 ), iQTY INT , orderId INT , dtCreate DATETIME ) INSERT INTO #ORDER ( fName , lName , ShipAddress , dtCreate ) SELECT 'Dilip' , 'SINGH' , 'New Delhi' , GETDATE () UNION ALL SELECT 'Nirmit' , 'katiyar' , 'Mumbai' , GETDATE () UNION ALL SELECT 'Raj' , 'Dongra' , 'Jharkhand' , GETDATE () UNION ALL SELECT 'Salim' , 'safi' , 'Muradnagar UP' , GETDATE () INSERT INTO #ORDER_DETAILS ( productName , pPrice , iQTY , orderId , dtCreate ) SELE

Constraints in sql server

Constraints   - Constraints are the rules enforced on data columns on table. This ensures the accuracy and reliability of the data in the database. Constraints define some conditions that restricts the column to remain true while inserting or updating or deleting data in column. Constraints can be defined in two ways   1) The constraints can be specified immediately after the column definition. This is called column-level definition.   2) The constraints can be specified after all the columns are defined. This is called table-level definition.   Types of Constraints in SQL-Server NOT NULL - This constraint is responsible for a column to confirm that a column cannot have a null value. DEFAULT – This constraint provides a default value when specified non for this column. UNIQUE - This constraint insure that each row for the column has different value. PRIMARY KEY - Primary key constraint is a combination of a NOT NULL constraint and a UNIQUE constra

NOT NULL constraint in sql server

NOT NULL- This constraint is responsible for a column to confirm that a column cannot have a null value. Example- Following we create new table PRODUCT and add six columns where ID, SKU, TITLE, PRICE specify not to accept NULLs. CREATE TABLE PRODUCT ( ID INT NOT NULL, SKU VARCHAR ( 20 ) NOT NULL, TITLE VARCHAR ( 200 ) NOT NULL, PRICE MONEY NOT NULL, DISCRIPTION VARCHAR ( 2000 )   NULL, DTCREATE DATETIME NULL ) If PRODUCT table already created, then to add a NOT NULL constraints to SKU column we use following query.   ALTER TABLE PRODUCT   ALTER COLUMN SKU  VARCHAR ( 20 ) NOT NULL