数据库访问 [英] DATABASE ACCESS

查看:80
本文介绍了数据库访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的工作创建一种独特的注册表格

即将到来的节日圣诞节

派对。

桌上将有60张桌子,最多可容纳10人。


如何编写一些代码来支持这个?我需要能够看到

座位数和给定桌位的任何可用座位的人数。怎么

我可以设置我的数据库

并提取信息给我想要的东西。

I am trying to create a unique type of registration form for my job
upcoming Holiday Christmas
Party. There will be 60 tables for seatings with 10 people max at
table.

How can I write some codes to support this? I need to be able to see
the number of
people who are seating and any available seats at a given table. How
can I set my database
and pull the information to give what I want.

推荐答案

使用查找表。


DDL:

CREATE TABLE Person(

PersonID smallint主键身份,

PersonName varchar(100)NOT NULL DEFAULT''''




CREATE TABLE PartyTable(

PartyTableID tinyint主键标识,

TableName varchar(20)NOT NULL DEFAULT''''



CREATE TABLE PTLookup(

PersonID smallint外键引用Person(PersonID),

PartyTableID tinyint外键引用PartyTable(PartyTableID)



GO

SET IDENTITY_INSERT PartyTable ON

DECLARE @i tinyint; SET @i = 1

WHILE @ i< 11

BEGIN

插入PartyTable(

PartyTableID,TableName

)价值(

@i,''表''+ CAST(@i as char)



SET @ i = @ i + 1

结束



图:


表:

PartyTableID(PK) - 。< br $>
PartyTableName`。

\ PTLookup:

` ----- PartyTableID(FK)

, - ------- PersonID(FK)

/

PersonID(PK)-----''

PersonName


QUERIES:

找到坐在指定餐桌旁的人:

SELECT PersonName FROM Person

INNER JOIN PTLookup

ON Person.PersonID = PTLookup.PersonID

INNER JOIN PartyTable

ON PTLookup.PartyTableID = PartyTable.PartyTableID

WHERE

PartyTable.PartyTableID = 3

在每张桌子上统计:

SELECT

PartyTable.TableName,COUNT(PTLookup.PersonID)

FR OM

PartyTable INNER JOIN PTLookup

ON PartyTable.PartyTableID = PTLookup.PartyTableID

GROUP BY

PartyTable.TableName

雷在工作


" IC1(SW / AW)" < sc ****** @ gmail.com写信息

新闻:11 ********************* @ i42g2000cwa。 googlegro ups.com ...
With a lookup table.

DDL:
CREATE TABLE Person (
PersonID smallint primary key identity,
PersonName varchar(100) NOT NULL DEFAULT ''''
)

CREATE TABLE PartyTable (
PartyTableID tinyint primary key identity,
TableName varchar(20) NOT NULL DEFAULT ''''
)
CREATE TABLE PTLookup (
PersonID smallint foreign key references Person(PersonID),
PartyTableID tinyint foreign key references PartyTable(PartyTableID)
)
GO
SET IDENTITY_INSERT PartyTable ON
DECLARE @i tinyint; SET @i = 1
WHILE @i < 11
BEGIN
INSERT INTO PartyTable (
PartyTableID, TableName
) VALUES (
@i, ''Table '' + CAST(@i as char)
)
SET @i=@i+1
END


DIAGRAM:

Table:
PartyTableID (PK)--.
PartyTableName `.
\ PTLookup:
`-----PartyTableID (FK)
,--------PersonID (FK)
/
PersonID (PK)-----''
PersonName

QUERIES:
Find people sitting at a specified table:

SELECT PersonName FROM Person
INNER JOIN PTLookup
ON Person.PersonID = PTLookup.PersonID
INNER JOIN PartyTable
ON PTLookup.PartyTableID = PartyTable.PartyTableID
WHERE
PartyTable.PartyTableID = 3
Get a count at each table:
SELECT
PartyTable.TableName, COUNT(PTLookup.PersonID)
FROM
PartyTable INNER JOIN PTLookup
ON PartyTable.PartyTableID = PTLookup.PartyTableID
GROUP BY
PartyTable.TableName
Ray at work


"IC1(SW/AW)" <sc******@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...

>我正在尝试为我的工作创建一种独特的注册表格

即将到来的节日圣诞节

派对。

桌上将有60张桌子,最多可容纳10人。


如何编写一些代码来支持这个?我需要能够看到

座位数和给定桌位的任何可用座位的人数。如何

我可以设置我的数据库

并提取信息以提供我想要的内容。
>I am trying to create a unique type of registration form for my job
upcoming Holiday Christmas
Party. There will be 60 tables for seatings with 10 people max at
table.

How can I write some codes to support this? I need to be able to see
the number of
people who are seating and any available seats at a given table. How
can I set my database
and pull the information to give what I want.



IC1(SW / AW)写道:
IC1(SW/AW) wrote:

我正在尝试为我的工作创建一种独特的注册表格

即将到来的节日圣诞节

派对。

桌上将有60张桌子,最多可容纳10人。


如何编写一些代码来支持这个?我需要能够看到

座位数和给定桌位的任何可用座位的人数。如何

我可以设置我的数据库

并提取信息以提供我想要的内容。
I am trying to create a unique type of registration form for my job
upcoming Holiday Christmas
Party. There will be 60 tables for seatings with 10 people max at
table.

How can I write some codes to support this? I need to be able to see
the number of
people who are seating and any available seats at a given table. How
can I set my database
and pull the information to give what I want.



如果Ray'的DDL在你尝试时产生错误,你应该告诉我们你正在使用什么

数据库。他为SQL Server提供了Transact-SQL代码。它不会为其他类型的数据库工作。


-

Microsoft MVP - ASP / ASP。 NET

请回复新闻组。我的From

标题中列出的电子邮件帐户是我的垃圾邮件陷阱,因此我不经常检查它。通过发布到新闻组,您将获得更快的回复。

If Ray''s DDL generates errors when you try it, you should tell us what
database you are using. He provided Transact-SQL code for SQL Server. it
won''t work for other types of databases.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don''t check it very often. You will get a
quicker response by posting to the newsgroup.




" IC1(SW / AW )" < sc ****** @ gmail.com写信息

新闻:11 ********************* @ i42g2000cwa。 googlegro ups.com ...

"IC1(SW/AW)" <sc******@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...

>我正在尝试为我的工作创建一种独特的注册表格

即将到来的节日圣诞节

派对。

桌上将有60张桌子,最多可容纳10人。
>I am trying to create a unique type of registration form for my job
upcoming Holiday Christmas
Party. There will be 60 tables for seatings with 10 people max at
table.



谢谢,但我要去圣诞节。

Thanks but I''m going away at Christmas.


如何编写一些代码来支持这个?我需要能够看到

座位数和给定桌位的任何可用座位的人数。如何

我可以设置我的数据库

并提取信息以提供我想要的内容。
How can I write some codes to support this? I need to be able to see
the number of
people who are seating and any available seats at a given table. How
can I set my database
and pull the information to give what I want.



这篇关于数据库访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆