Full-Stack freelance Umbraco developer in the UK.

George Phillipson - Freelance Umbraco developer

Mssql sequence numbers with begin transaction

CREATE SCHEMA Company;  
--CREATE SEQUENCE Company.InvoiceNumber  
--	AS int  
--		START WITH 1  
--		INCREMENT BY 1 ;
USE [AdvancedDatabases]
GO
/****** Object:  Table [dbo].[InvoiceNumber]    Script Date: 13/06/2017 00:13:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[InvoiceNumber](
	[InvoiceNumber] [int] NOT NULL,
	[InvoiceDate] [smalldatetime] NULL,
 CONSTRAINT [PK_InvoiceNumber] PRIMARY KEY CLUSTERED 
(
	[InvoiceNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[InvoiceNumber] ADD  CONSTRAINT [DF_InvoiceNumber_InvoiceDate]  DEFAULT (getdate()) FOR [InvoiceDate]
GO
USE [AdvancedDatabases]
GO
/****** Object:  Table [dbo].[JobDetails]    Script Date: 13/06/2017 00:15:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[JobDetails](
	[JobId] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
	[InvoiceNumber] [int] NOT NULL,
	[JobDescription] [nvarchar](500) NULL,
	[NetCost] [smallmoney] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[JobDetails] ADD  CONSTRAINT [DF_JobDetails_JobId]  DEFAULT (newid()) FOR [JobId]
GO
Invoice example

Please enter your comment.