资源描述:
《图书数据库脚本范文》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、usemastergo-ifexists(select*fromsysdatabaseswherename=,MyBookShop,)-begin-dropdatabaseMyBookShop—end-go-execsp_attach_db@dbname=N'MyBookShop;-©filename1=N'D:MyBookShop.mdf,-@filename2=N'D:MyBookShop_log.ldf;-goifexists(select*fromsysdatabaseswherename=,MyLibrary,)begindropdat
2、abaseMyLibraryendgocreatedatabaseMyLibrarygouseMyLibrarygoifexists(select*fromsysobjectswherename=fPublishers1)begindroptablePublishersendgocreatetablePublishers(PublisherlDintprimarykeyidentity(l,l)notnull,Namenvarchar(KX))notnull)go/****************例中J举山I*******************/c
3、reatetableCategories(CategoryIDintprimarykeyidentity(lJ)notnull,Namenvarchar(lOO)notnull,ParentIDint)g°altertableCategoriesaddconstraintFK_ParentIDforeignkey(ParentID)referencesCategories(CategorylD)go/*£*•土*1^IIII*1*•土*1^•土*1^/严柏水*和苓苓杉和粉水*木冏弔来柑水水卫和朴林柑水水水2/createtableBooks(Book
4、IDintprimarykeyidentity(3000,1)notnull,Titlenvarchar(200)notnull,Authornvarchar(200)notnull,CategoryIDintreferencesCategories(Categoryld)notnull,PublisherlDintreferencesPublishers(Publisherld)notnull,UnitPricemoneynotnull,PublishDatedatetimenotnull,ISBNnvarchar(50)notnull,Words
5、Countintnotnull,ContentDescriptionnvarchar(max),Statenvarchar(10)notnull,TopperDatedatetimedefault(getdate()),UnTopperDatedatetimenull,Clicksintnotnulldefault(O))createtableReaderReaderIDintprimarykeyidentity(IOOOJ)notnull,Namenvarchar(20)notnull,Passwordvarchar(20)default(*123
6、456*)notnull,Sexvarchar(20)notnull,Addressnvarchar(200)notnull,Phonevarchar(20)notnull,Mailvarchar(50)notnull,gocreatetableReaderCardsCardIDvarchar(10)primarykeynotnull,Foregiftmoneydefault(lOO)notnull,ReaderIDintreferencesReader(ReaderlD)notnull)gocreatetableBoiTowInfoBIIDintp
7、rimarykeyidentity(lJ)notnull,BookIDintreferencesBooks(BooklD)notnull,CardIDvarchar(lO)referencesReaderCards(CardlD)notnull,BorrowDatedatetimenotnull,BackDatedatetimenullg°createtableKeepBorrowInfo(KBIIDintprimarykeyidentity(lj)notnull,BIIDintreferencesBorrowInfo(BIID)notnull,Bo
8、okIDintreferencesBooks(BooklD)notnull,CardIDvarchar(10