Created
January 21, 2015 21:44
-
-
Save mythz/6f336094f8dd07c22d91 to your computer and use it in GitHub Desktop.
TestJoinSupportForORMLite SqlServer SP and tables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--drop table [OrderDetail] | |
--drop table [Order] | |
--drop table [Address] | |
--drop table [ProUser] | |
DROP TABLE [dbo].[Address] | |
GO | |
DROP TABLE [dbo].[Order] | |
GO | |
DROP TABLE [dbo].[ProUser] | |
GO | |
CREATE TABLE [dbo].[ProUser]( | |
[Id] [varchar](300) NOT NULL, | |
[Password] [nchar](10) NULL, | |
[UserType] [int] NULL, | |
CONSTRAINT [PK_ProUser] PRIMARY KEY CLUSTERED | |
([Id] 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 | |
CREATE TABLE [dbo].[Order]( | |
[Id] [int] IDENTITY(1,1) NOT NULL, | |
[ProUserId] [varchar](300) NOT NULL, | |
[Details] [varchar](300) NULL, | |
[ItemId] [int] NOT NULL, | |
CONSTRAINT [PK_Order] PRIMARY KEY CLUSTERED | |
([Id] ASC) | |
WITH | |
(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] | |
) ON [PRIMARY] | |
ALTER TABLE [dbo].[Order] WITH CHECK ADD CONSTRAINT [FK_Order_ProUser] FOREIGN KEY([ProUserId]) | |
REFERENCES [dbo].[ProUser] ([Id]) | |
GO | |
CREATE TABLE [dbo].[Address]( | |
[Id] [int] IDENTITY(1,1) NOT NULL, | |
[ProUserId] [varchar](300) NOT NULL, | |
[StreetName] [varchar](300) NULL, | |
[ZipCode] [int] NULL, | |
CONSTRAINT [PK_Address] PRIMARY KEY CLUSTERED | |
( | |
[Id] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] | |
) ON [PRIMARY] | |
ALTER TABLE [dbo].[Address] WITH CHECK ADD CONSTRAINT [FK_Address_ProUser] FOREIGN KEY([ProUserId]) | |
REFERENCES [dbo].[ProUser] ([Id]) | |
GO | |
ALTER TABLE [dbo].[Address] CHECK CONSTRAINT [FK_Address_ProUser] | |
GO | |
DROP PROCEDURE [dbo].[TestJoinSupportForORMLite] | |
GO | |
CREATE PROCEDURE [dbo].[TestJoinSupportForORMLite] | |
@UserId varchar(300) | |
AS | |
BEGIN | |
SET NOCOUNT ON; | |
select ProUser.Id, [Address].StreetName, [Address].ZipCode, [Order].Details from | |
ProUser | |
join | |
[Address] | |
on | |
ProUser.Id = [Address].ProUserId | |
join | |
[Order] | |
on | |
[Order].ProUserId = ProUser.id | |
where ProUser.Id = @UserId | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment