Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet331/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   327   328   329   330   331   332   333   334   ...   443
Bog'liq
BookSQL

 

CHAPTER 8

 

Data Modification



 

 291

5

Update all orders in the dbo.Orders table that were placed by United Kingdom customers and set 

their shipcountryshipregion, and shipcity values to the countryregion, and city values of the corre-

sponding customers.



6

When you’re done, run the following code for cleanup.

IF OBJECT_ID('dbo.Orders', 'U') IS NOT NULL DROP TABLE dbo.Orders; 

IF OBJECT_ID('dbo.Customers', 'U') IS NOT NULL DROP TABLE dbo.Customers;



Solutions

This section provides solutions to the preceding exercises.



1-1

Make sure that you are connected to the TSQL2012 database.

USE TSQL2012;

Use the following INSERT VALUES statement to insert a row into the Customers table with the 

values provided in the exercise.

INSERT INTO dbo.Customers(custid, companyname, country, region, city) 

  VALUES(100, N'Coho Winery', N'USA', N'WA', N'Redmond');

1-2

One way to identify customers who placed orders is to use the EXISTS predicate, as the following 

query shows.

  SELECT custid, companyname, country, region, city 

  FROM Sales.Customers AS C 

  WHERE EXISTS 

    (SELECT * FROM Sales.Orders AS O 

     WHERE O.custid = C.custid);

To insert the rows returned from this query into the dbo.Customers table, you can use an INSERT 

SELECT statement as follows.

INSERT INTO dbo.Customers(custid, companyname, country, region, city) 

  SELECT custid, companyname, country, region, city 

  FROM Sales.Customers AS C 

  WHERE EXISTS 

    (SELECT * FROM Sales.Orders AS O 

     WHERE O.custid = C.custid);

www.it-ebooks.info





Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   327   328   329   330   331   332   333   334   ...   443




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish