Tuesday, October 9, 2007

Update SQL Syntax

Update query SQL Syntax

Allows you to update records in a database. You typically will want to update a record using the where clause.

UPDATE tablename
SET columnfield = [parameter/value], columnfield2 = [parameter2/value2] = expression2, ....
[ WHERE expression ]
[ LIMIT limit_amount ]

Example:
Note, this has been altered for protection

-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Joe Bailey
-- Create date: 10/09/2007
-- Description: Updates the values from the xyz database
-- =============================================
CREATE PROCEDURE [dbo].[xyz_Update]
-- Add the parameters for the stored procedure here
@xyzID integer,
@xyzName nvarchar(200),
@xyzPage nvarchar(500),
@xyzPageTitle nvarchar(500),
@xyzMetaDescription nvarchar(1000),
@xyzMetaKeywords nvarchar(1000)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
UPDATE xyzSET
xyzName = @xyzName,
xyzPage = @xyzPage,
xyzPageTitle = @xyzPageTitle,
xyzMetaDescription = @xyzMetaDescription,
xyzMetaKeywords = @xyzMetaKeywords
WHERE xyzID = @xyzID
END
GO

No comments: