SQL 2000 Transact – Northwind Database

SQL Transact – Northwind Database

Northwind is free.  With SQL server, Microsoft has provided THE most marvellous and comprehensive database.  Another benefit of Northwind is that once SQL is installed, then you have a copy of Northwind and so you can try my examples.

SQL Northwind built-in databaseOnce you have finished installing SQL, then start the Query Browser, and you will see the databases in the object browser. 

Tip: Once inside the Query Browser, press F8 (Function key eight) to toggle the Object Browser window.

The Northwind database structure is a series of User Tables, for example, Categories, Customers and Employees.

If we home in on the Customers, then you can see the Columns or field names and their characteristics.   For instance, CustomerID is exactly 5 characters and it cannot be Null.  Whereas City can be a variable number of characters – up to 15, moreover, City could be Null or blank.

The diagram on the right also show folders with Indexes, Constraints and Dependencies.  You can also see in passing that their are other tables in the Northwind Database, for example, Employees and Order Details.

GuyCustomer is of course, non-standard, just a table I created to experiment.

In the following section I will be concentrating on the SQL Transact statements, and not worrying about database design.  Remember all the fields have been created for us, Northwind is there for us to query.

Important Footnote: Backup and Restore

If Northwind were a real live database, ‘Best Practice’ would say ‘Backup regularly’.  Guy says backup Northwind, so that you can go back and start again, particularly when you are testing INSERT or DELETE statements. 

While there are betters ways to backup Northwind, I have gone for the simplest method.

Statement to Backup, and protect Northwind

 

— SQL statement to BACKUP the Northwind Database to c:\ drive

BACKUP DATABASE Northwind
TO DISK = ‘C:\GuyNorthwind.bak’

 

Oh yes, and if want to get it back – here is the restore command.

 

— SQL statement to RESTORE the Northwind Database from C:\ drive

RESTORE DATABASE Northwind
FROM DISK= ‘C:\GuyNorthwind.bak’

 

 

 


 See also