JayBeeOH

SampleDBCreateNLoad.sql (SampleDB)

Jul 13th, 2015
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.63 KB | None | 0 0
  1. --'------------------------------------------------------------------------------------------
  2. --'           Notice of My Copyright and Intellectual Property Rights
  3. --'
  4. --' Any intellectual property contained within the program by Joseph L. Bolen remains the
  5. --' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
  6. --' publish or provide such intellectual property to any other person or entity for any
  7. --' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
  8. --'
  9. --'                 Copyright © 2015. All rights reserved.
  10. --'        All trademarks remain the property of their respective owners.
  11. --'-------------------------------------------------------------------------------------------
  12. --' Name:       SampleDBCreateNLoad.sql (SampleDB)
  13. --'
  14. --' Author:     Joseph L. Bolen
  15. --' Date Created:   Jul 2015
  16. --'
  17. --' Description:    Simple two table database.
  18. --'
  19. --'                 Documentation is at:
  20.  
  21. --'                   App's Visual Basic .NET code is at http://pastebin.com/ajgYQYMc
  22. --'                   Video tutorial at YouTube: http://www.youtube.com/user/bolenpresents
  23. --'-------------------------------------------------------------------------------------------
  24.  
  25.  
  26. USE master;
  27. GO
  28.  
  29. IF  EXISTS (
  30.     SELECT name
  31.         FROM sys.databases
  32.         WHERE name = N'SampleDB'
  33. )
  34. DROP DATABASE SampleDB;
  35. GO
  36.  
  37. --Modify location of database for your environment.
  38. CREATE DATABASE SampleDB
  39. ON (NAME=SampleDB, FILENAME='U:\Databases\SQLDatabases\SampleDB.mdf')
  40. LOG ON (NAME=SampleDB_log, FILENAME='U:\Databases\SQLDatabases\SampleDB.ldf');
  41. GO
  42.  
  43. USE SampleDB;
  44. GO
  45.  
  46. CREATE TABLE Customers
  47. (
  48. CustomerId int NOT NULL IDENTITY(1,1),
  49. CustomerName nvarchar(35) NOT NULL,
  50. CustomerContact nvarchar(35),
  51. Phone nvarchar(15),
  52. CONSTRAINT PK_CustomerId PRIMARY KEY (CustomerId)
  53. );
  54. GO
  55.  
  56. CREATE TABLE Orders
  57. (
  58. OrderId int NOT NULL IDENTITY(1,1),
  59. CustomerId int NOT NULL,
  60. OrderDate date,
  61. OrderQuantity int,
  62. CONSTRAINT PK_OrderId PRIMARY KEY (OrderId),
  63. CONSTRAINT FK_Orders_Customers FOREIGN KEY (CustomerId)
  64. REFERENCES Customers (CustomerId)
  65. );
  66. GO
  67.  
  68. USE SampleDB;
  69. GO
  70.  
  71. INSERT INTO Customers
  72. (
  73. CustomerName
  74. ,CustomerContact
  75. ,Phone
  76. )
  77. VALUES
  78. ('Widget Company',     'George Sprocket',   '555-555-1212'),
  79. ('Gadget Enterprise',  'Mike Griffin',      '555-555-1234'),
  80. ('Thingamajigs R''Us', 'Sally Peterson',    '555-555-9876');
  81. GO
  82.  
  83. USE SampleDB;
  84. GO
  85.  
  86. INSERT INTO Orders
  87. (
  88. CustomerId
  89. ,OrderDate
  90. ,OrderQuantity
  91. )
  92. VALUES
  93. (1, '2015-07-21',   125),
  94. (1, '2015-07-28',   200),
  95. (1, '2015-08-04',   125),
  96. (2, '2015-08-15',   200),
  97. (3, '2015-07-22',   50),
  98. (3, '2015-07-29',   75),
  99. (3, '2015-08-05',   100);
  100. GO
Advertisement
Add Comment
Please, Sign In to add comment