如何在MSSQL中创建最佳的数据库设计? [英] How to create the best database design in MSSQL?

查看:93
本文介绍了如何在MSSQL中创建最佳的数据库设计?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我现在正在学习所有关于数据库的知识。我只想问一下是否可以创建一个数据库表,总共有17个字段。相反,我应该为它创建一个单独的表吗?或者它是否更好?请为此建议更好的设计,或者我应该尝试实现关系数据库。我已经在下面提供了sql代码。



我尝试过:



Hi! I'm learning all about databases now. I just want to ask if it's okay to create a database table, where there are a total of 17 fields. And instead, should I create a separate table for it? or is it better as it is? Kindly advice a better design for this or if i should try implementing relational database to it. I have included the sql code below.

What I have tried:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[guitarItems](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[type] [varchar](50) NOT NULL,
	[brand] [varchar](50) NOT NULL,
	[model] [varchar](50) NOT NULL,
	[price] [float] NOT NULL,
	[image logo] [varchar](255) NULL,
	[item image1] [varchar](255) NULL,
	[item image2] [varchar](255) NULL,
	[description] [text] NOT NULL,
	[neck type] [varchar](100) NOT NULL,
	[body] [varchar](100) NOT NULL,
	[fretboard] [varchar](100) NOT NULL,
	[fret] [varchar](50) NOT NULL,
	[bridge] [varchar](100) NOT NULL,
	[neck pickup] [varchar](100) NOT NULL,
	[bridge pickup] [varchar](100) NOT NULL,
	[hardware color] [varchar](50) NOT NULL,
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] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
SET IDENTITY_INSERT [dbo].[guitarItems] ON
INSERT [dbo].[guitarItems] ([id], [type], [brand], [model], [price], [image logo], [item image1], [item image2], [description], [neck type], [body], [fretboard], [fret], [bridge], [neck pickup], [bridge pickup], [hardware color]) VALUES (1, N'Guitar', N'ESP', N'Alexi 600', 17000.00, N'../Images/guitarLogo.jpg, N'../Images/Guitar Brands/ESP Guitars/espAlexi600.jpg', N'../Images/Guitar Brands/ESP Guitars/espAlexi600StandingPosition.jpg',
			N' Hardcore instrument that is only fitting for the darkest of music.', N'Maple Neck', N'Mahogany Body',
			N'Maple Fretboard', N'24 Frets', N'Regular Control',N'Single Coil', N'Single Coil', N'White')
INSERT [dbo].[guitarItems] ([id], [type], [brand],[model], [price], [image logo], [item image1], [item image2], [description], [neck type], [body], [fretboard], [fret], [bridge], [neck pickup], [bridge pickup], [hardware color]) VALUES (2, N'Guitar, N'ESP', N'EC 50', 14000.00, N'../Images/guitarLogo2.jpg, N'../Images/Guitar Brands/ESP Guitars/espEC50.jpg', N'../Images/Guitar Brands/ESP Guitars/espEC50StandingPosition.jpg',
			N' Hardcore instrument that is only fitting for the darkest of music.', N'Maple Neck', N'Mahogany Body',
			N'Maple Fretboard', N'24 Frets', N'Regular Control',N'Single Coil', N'Single Coil', N'Grey and Black')


SET IDENTITY_INSERT [dbo].[guitarItems] OFF

推荐答案

BebeSaiyan说:
BebeSaiyan said:

我只想询问是否可以创建一个数据库表,其中总共有17个字段。

I just want to ask if it's okay to create a database table, where there are a total of 17 fields.

是。

BebeSaiyan说:
BebeSaiyan said:

相反,我应该为它创建一个单独的表吗?或者它是否更好?

And instead, should I create a separate table for it? or is it better as it is?

它更好。一个单独的表for(无论它是什么)不太可能是一个好主意。

It's better as it is. A separate table for "it" (whatever "it" is) is unlikely to be a good idea.

BebeSaiyan说:
BebeSaiyan said:

如果我应该尝试实现关系数据库

if i should try implementing relational database to it

我不确定你知道关系数据库是什么意思。我认为你的真正含义是我应该将规范化应用于数据库。这个问题的答案总是是。请参阅数据库规范化基础知识 [ ^ ]

另见@PIEBALDconsult的评论

I'm not sure that you know what is meant by a Relational Database. I think what you really mean is "Should I apply Normalization to the database". The answer to that question is invariably "Yes". See The Basics of Database Normalization[^]
See also the comments from @PIEBALDconsult

PIEBALDconsult说:
PIEBALDconsult said:

请不要在名称中加上SPACE。

尽量不要使用关键字作为名称。

不要多元化名字。

身份是污秽。

为什么当列不是N时用N指定你的字符串值?

Please do not put SPACEs in names.
Try not to use keywords as names.
Don't pluralize names.
Identities are filth.
Why specify your string values with N when the columns are not N?



我已经删除了对Identity列的评论,因为这是一个意见陈述,对使用Identity列的意见因开发人员而异。我建议你阅读这篇文章 - Aaron Bertrand:糟糕的习惯:在每张桌子上放置一个IDENTITY列 [ ^ ]


这篇关于如何在MSSQL中创建最佳的数据库设计?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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