Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet310/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   306   307   308   309   310   311   312   313   ...   443
Bog'liq
BookSQL

updating Data

T-SQL supports a standard UPDATE statement that allows you to update rows in a table. T-SQL also 

supports nonstandard uses of the UPDATE statement with joins and with variables. This section de-

scribes the various uses of the UPDATE statement.

www.it-ebooks.info



 

CHAPTER 8

 

Data Modification



 

 265

The examples I provide in this section are against copies of the Orders and OrderDetails tables 

from the Sales schema created in the dbo schema. Run the following code to create and populate 

those tables.

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

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

 

CREATE TABLE dbo.Orders 



  orderid        INT          NOT NULL, 

  custid         INT          NULL, 

  empid          INT          NOT NULL, 

  orderdate      DATETIME     NOT NULL, 

  requireddate   DATETIME     NOT NULL, 

  shippeddate    DATETIME     NULL, 

  shipperid      INT          NOT NULL, 

  freight        MONEY        NOT NULL 

    CONSTRAINT DFT_Orders_freight DEFAULT(0), 

  shipname       NVARCHAR(40) NOT NULL, 

  shipaddress    NVARCHAR(60) NOT NULL, 

  shipcity       NVARCHAR(15) NOT NULL, 

  shipregion     NVARCHAR(15) NULL, 

  shippostalcode NVARCHAR(10) NULL, 

  shipcountry    NVARCHAR(15) NOT NULL, 

  CONSTRAINT PK_Orders PRIMARY KEY(orderid) 

); 


 

CREATE TABLE dbo.OrderDetails 

  orderid   INT           NOT NULL, 



  productid INT           NOT NULL, 

  unitprice MONEY         NOT NULL 

    CONSTRAINT DFT_OrderDetails_unitprice DEFAULT(0), 

  qty       SMALLINT      NOT NULL 

    CONSTRAINT DFT_OrderDetails_qty DEFAULT(1), 

  discount  NUMERIC(4, 3) NOT NULL 

    CONSTRAINT DFT_OrderDetails_discount DEFAULT(0), 

  CONSTRAINT PK_OrderDetails PRIMARY KEY(orderid, productid), 

  CONSTRAINT FK_OrderDetails_Orders FOREIGN KEY(orderid) 

    REFERENCES dbo.Orders(orderid), 

  CONSTRAINT CHK_discount  CHECK (discount BETWEEN 0 AND 1), 

  CONSTRAINT CHK_qty  CHECK (qty > 0), 

  CONSTRAINT CHK_unitprice CHECK (unitprice >= 0) 

); 


GO 

 

INSERT INTO dbo.Orders SELECT * FROM Sales.Orders; 



INSERT INTO dbo.OrderDetails SELECT * FROM Sales.OrderDetails;


Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   306   307   308   309   310   311   312   313   ...   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