search
HomeDatabaseMysql Tutorial数据库课程设计--“茶咖啡”销售管理系统总结

为期一周的数据库课程设计终于完工, 总结一些经验和教训。发现基础的知识还是要时刻记在心中,知识不基础,何谈去开发?因为做什么东西都首先要一定的目标,计划,以及做到东西要做到那个程度,这方面一点要先在脑子里有一个印象,然后才能用所学的知识点去

为期一周的数据库课程设计终于完工, 总结一些经验和教训。发现基础的知识还是要时刻记在心中,知识不基础,何谈去开发?因为做什么东西都首先要一定的目标,计划,以及做到东西要做到那个程度,这方面一点要先在脑子里有一个印象,然后才能用所学的知识点去发挥, 因此知识点一点要掌握牢固,自己在设计课程设计的过程中,发现写好的数据库语言一点运行,就会出现这个那个的问题。然后从头去寻找问题的源头,才发现表的主键和外键设置出了问题。然后琢磨半天,突然意识到到底是什么主键和外键?

两个的定义和作用到底是什么?,这才发现以前上课所学的知识现在非所用,知其然不知其所以然。

 

键:唯一标识表中的所有行的一个列或一组列。
主键不允许空值。不能存在具有相同的主键值的两个行,因此主键值总是唯一标识单个行。
表中可以有不止一个键唯一标识行,每个键都称作候选键。只有一个候选键可以选作表的主键,所有其它候选键称作备用键。尽管表不要求具有主键,但定义主键是很好的做法。
外键(FK): 是用于建立和加强两个表数据之间的链接的一列或多列。通过将保存表中主键值的一列或多列添加到另一个表中,可创建两个表之间的链接。这个列就成为第二个表的外键。
例如:成绩表中的学号不能做成绩表的主键(因为一个学生可以有多行成绩数据),但每行的学号和学生表中的学号相对应,并且学生表中的学号是学生表的主键,则称成绩表中的学号是学生表的外键。(典型的一对多关系)

写SQL语言还出现了这几种情况:

(1)创建一个新表的时候,把英文括号写成了中文,找错误找了半小时。

(2)新表第一次录入数据之后,第二次不能再次录入,已经造成重复。

(3)没有注意主键不能为空值。

(4)外键设置时约束项没有搞清楚。

 

通过这次课程设计发现这其中需要的很多知识我们没有接触过,上网查找资料的时候发现我们以前所学到的仅仅是皮毛,还有很多需要我们掌握的东西我们根本不知道。同时也发现有很多已经学过的东西我们没有理解到位,不能灵活运用于实际,不能很好的用来解决问题,这就需要自己不断的大量的实践,通过不断的自学,不断地发现问题,思考问题,进而解决问题。在这个过程中我们将深刻理解所学知识,同时也可以学到不少很实用的东西。

 

CREATE TABLE BILL
(
   BILL_num  char(10)   primary key ,
   BILL_time  char(8)    NOT NULL,
   BILL_paymoney  char(10)  NOT NULL,
   BILL_summoney char(10)   NOT NULL,
   BILL_goodstype  char(10)     NOT NULL,
   BILL_unitprice char (10)  NOT NULL,
   Customers_num char  (10),
   MemberID char (11) ,
)
CREATE TABLE Member
(
MemberID char(11) primary key,
MemberNAme char(10)  NOT NULL,
MemberSex char (2)  NOT NULL,
Memberphone varchar(12)  NOT NULL,
BILL_num char(10) NOT NULL, 
constraint MemberSex check(MemberSex='男'or MemberSex='女'),
foreign key (BILL_num ) references BILL(BILL_num)
)
CREATE TABLE Customers

(
   Customers_num char  (10) primary key  ,
   Customers_name char (10)  NOT NULL,
   BILL_num char(10) NOT NULL,
   foreign key (BILL_num ) references BILL(BILL_num)
)
CREATE TABLE Goods
(    
   Goods_num char(4) primary key,
   Goods_name char (10) ,
   Goods_stock char(10),
   BILL_num char(10),
   foreign key (BILL_num ) references BILL(BILL_num)
)
go
insert  into  BILL(BILL_num, BILL_time,BILL_paymoney ,BILL_summoney, BILL_goodstype ,BILL_unitprice ,MemberID,Customers_num)
values('2014010101','20140101','100','50','蓝山','30','20140101001','Null')
insert  into  BILL(BILL_num, BILL_time,BILL_paymoney ,BILL_summoney, BILL_goodstype ,BILL_unitprice ,MemberID ,Customers_num)
values('2014010102','20140101','100','50','炭烧','35','20140202002','Null')
insert  into  BILL(BILL_num, BILL_time,BILL_paymoney ,BILL_summoney, BILL_goodstype ,BILL_unitprice ,MemberID,Customers_num )
values('2014010103','20140101','100','50','美式','40','20140310003','Null')
insert  into  BILL(BILL_num, BILL_time,BILL_paymoney ,BILL_summoney, BILL_goodstype ,BILL_unitprice ,MemberID ,Customers_num)
values('2014010104','20140101','100','50','拿铁','45','20140404004','Null')
insert  into  BILL(BILL_num, BILL_time,BILL_paymoney ,BILL_summoney, BILL_goodstype ,BILL_unitprice ,MemberID ,Customers_num)
values('2014010105','20140101','100','50','摩卡','50','20141001005','Null')
insert  into  BILL(BILL_num, BILL_time,BILL_paymoney ,BILL_summoney, BILL_goodstype ,BILL_unitprice ,MemberID, Customers_num)
values('2014010106','20140101','100','50','卡布奇诺','55','20141101006','Null')
insert  into  BILL(BILL_num, BILL_time,BILL_paymoney ,BILL_summoney, BILL_goodstype ,BILL_unitprice ,MemberID, Customers_num)
values('2013010101','20140101','100','50','卡布奇诺','55','Null','2014110106')
insert  into  BILL(BILL_num, BILL_time,BILL_paymoney ,BILL_summoney, BILL_goodstype ,BILL_unitprice ,MemberID, Customers_num)
values('2013010102','20140101','100','50','卡布奇诺','55','Null','2014110106')

insert  into Member(MemberID,MemberNAme,MemberSex,Memberphone,BILL_num) 
values ('20140101001','李一','男','15832578651','2014010101')
insert  into Member(MemberID,MemberNAme,MemberSex,Memberphone,BILL_num) 
values ('20140202002','李二','女','15832578652','2014010102')
insert  into Member(MemberID,MemberNAme,MemberSex,Memberphone,BILL_num) 
values ('20140310003','李三','男','15832578653','2014010103')
insert  into Member(MemberID,MemberNAme,MemberSex,Memberphone,BILL_num) 
values ('20140404004','李四','女','15832578654','2014010104')
insert  into Member(MemberID,MemberNAme,MemberSex,Memberphone,BILL_num) 
values ('20141001005','李五','男','15832578655','2014010105')
insert  into Member(MemberID,MemberNAme,MemberSex,Memberphone,BILL_num)
values ('20141101006','李六','女',【本文来自鸿网互联 (http://www.68idc.cn)】'15832578656','2014010106')

insert  into Goods(Goods_num ,Goods_name ,Goods_stock ,BILL_num )
values('1','蓝山','10','2014010101')                                                    
insert  into Goods(Goods_num ,Goods_name ,Goods_stock ,BILL_num )
values('2','炭烧','10','2014010102')
insert  into Goods(Goods_num ,Goods_name ,Goods_stock ,BILL_num )
values('3','美式','10','2014010103')
insert  into Goods(Goods_num ,Goods_name ,Goods_stock ,BILL_num )
values('4','拿铁','10','2014010104')
insert  into Goods(Goods_num ,Goods_name ,Goods_stock ,BILL_num )
values('5','摩卡','10','2014010105')
insert  into Goods(Goods_num ,Goods_name ,Goods_stock ,BILL_num )
values('6','卡布奇诺','10','2014010106')

insert  into Customers( Customers_num,Customers_name,BILL_num )
values ('01','王一','2013010101')
insert  into Customers( Customers_num,Customers_name,BILL_num )
values ('02','王二','2013010102')



实验结果:会员信息:

 

\

商品信息:

\

顾客信息:

\

账单信息:

\

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How to Grant Permissions to New MySQL UsersHow to Grant Permissions to New MySQL UsersMay 09, 2025 am 12:16 AM

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

How to Add Users in MySQL: A Step-by-Step GuideHow to Add Users in MySQL: A Step-by-Step GuideMay 09, 2025 am 12:14 AM

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

MySQL: Adding a new user with complex permissionsMySQL: Adding a new user with complex permissionsMay 09, 2025 am 12:09 AM

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

MySQL: String Data Types and CollationsMySQL: String Data Types and CollationsMay 09, 2025 am 12:08 AM

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

MySQL: What length should I use for VARCHARs?MySQL: What length should I use for VARCHARs?May 09, 2025 am 12:06 AM

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.

MySQL BLOB : are there any limits?MySQL BLOB : are there any limits?May 08, 2025 am 12:22 AM

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

MySQL : What are the best tools to automate users creation?MySQL : What are the best tools to automate users creation?May 08, 2025 am 12:22 AM

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

MySQL: Can I search inside a blob?MySQL: Can I search inside a blob?May 08, 2025 am 12:20 AM

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools