Relational databases
SQL Server

SQL Server is made by Microsoft the Express version is free. When you install SQL Server, you will get the SQL Server Configuration Manager, which you can use to start and stop the services. You can also install the SQL Server Management Studio, which you can use to handle databases. So the Management Studio is a graphical SQL Client for SQL Server.

SQL Server Express Installation
  1. Download the setup file from https://www.microsoft.com/en-us/download/confirmation.aspx?id=101064
  2. Start the installation and choose Custom
    install image
  3. Choose the folder (Default is ok)
  4. Choose New SQL Server stand-alone ....
    install image
  5. Check that all operations are passed and choose Next
    install image
  6. Make the choices which are describe in below image
    install image
  7. You can accept the suggested name for your server
    install image
  8. Choose Manual for all options below
    install image
  9. Choose Mixed Mode and add a password which you can remember(it will the password for your SQL Server administrator sa )
    install image
  10. Installation is ready and you can close it
    install image
SQL Server Management Studio Installation
  1. After installing SQL Server, you will be back on the startup which you can see below. Choose Install SQL Server Management Tools.
    install image
  2. Now you will redirected to web-page. Choose Free Download for SQL Server Management Studio (SSMS) 18.10
  3. After downloading execute the setup-file and you will below window. Click Install
    install image
SQL Server Configuration Manager

You can use the Configuration Manager to start and stop services
install image

The SQL Server -Service should be running every time you want to use your SQL Server. And if you want to connect to your SQL Server database with your applications, also the SQL Server Browser-Service should be running.
install image

SQL Server Management Studio

You can use Management Studio to handle your databases. When you start it you will see below window. You can connect(Authenticate) with your Windows User or with SQL Server User accounts.
install image

Example

Here is an example how to create a database (named netshop) and a user(named netuser) and how to give proviles to the netshop-database to the netuser.

  1. Start your Server and Connect with Management studio (using user sa)
  2. Clikc the plus sign left from "Security"
  3. Right Click Logins and choose "New Login"
    • Fill name netuser
    • Choose SQL Server authentication
    • Fill the password
    • Remove "Enforce password policy" (in production you can leave it active)
    • Click OK

  4. Right Click the "Databases" and choose "New Database" fill the name "netshop" and click OK
  5. Right Click netshop and choose properties and choose Files
  6. Click the ellipses beside Owner and choose Browse
  7. Choose netuser (as the owner) and click OK

Login in using user netuser and create tables to the database netshop.

  1. Login
  2. Click the plus sign left from Databases
  3. Right Click netshop and Choose New Query
  4. Copy-Paste below codes and execute them
    CREATE TABLE  Customers  (
       id_Customers  INT NOT NULL IDENTITY,
       first_name  varchar(50) DEFAULT NULL,
       last_name  varchar(50) DEFAULT NULL,
       street_address  varchar(255) DEFAULT NULL,
       postnumber  char(5) DEFAULT NULL,
      PRIMARY KEY ( id_Customers )
    );
    CREATE TABLE  Products  (
       id_Products  INT NOT NULL IDENTITY,
       product_name  varchar(50) DEFAULT NULL,
       manufacturer  varchar(255) DEFAULT NULL,
       model  varchar(255) DEFAULT NULL,
      PRIMARY KEY ( id_Products )
    ) ;
    CREATE TABLE  Orders  (
       id_Orders  INT NOT NULL IDENTITY,
       id_Products  INT NOT NULL DEFAULT '0',
       id_Customers  INT NOT NULL DEFAULT '0',
       order_day  date DEFAULT NULL,
       amount  INT DEFAULT NULL,
      PRIMARY KEY ( id_Orders ),
      FOREIGN KEY (id_Customers) REFERENCES Customers,
      FOREIGN KEY (id_Products) REFERENCES Products
    ) ;
    
    INSERT INTO Customers (first_name,last_name,street_address,postnumber) VALUES ('Jim','Smith','Kotkantie 1','90650');
    INSERT INTO Customers (first_name,last_name,street_address,postnumber) VALUES ('Lisa','Simpson','Uusikatu 1','90100');
    INSERT INTO Customers (first_name,last_name,street_address,postnumber) VALUES ('Ann','Jones','Uusikatu 4','90100');
    INSERT INTO Customers (first_name,last_name,street_address,postnumber) VALUES ('Bruce','Wayne','Aleksanterinkatu 4','01250');
    
    INSERT INTO Products (product_name,manufacturer,model) VALUES ('Laptop','Lenovo','Ideapad');
    INSERT INTO Products (product_name,manufacturer,model) VALUES ('Laptop','Asus','U31XU');
    INSERT INTO Products (product_name,manufacturer,model) VALUES ('Camera','Canon','G11');
    INSERT INTO Products (product_name,manufacturer,model) VALUES ('Navigator','TomTom','GoLive');
    
    INSERT INTO Orders VALUES (4,1,'2013-05-20',1);
    INSERT INTO Orders VALUES (2,2,'2013-05-18',1);
    INSERT INTO Orders VALUES (3,3,'2013-05-17',2);
    INSERT INTO Orders VALUES (1,4,'2013-05-16',1);
    INSERT INTO Orders VALUES (3,1,'2013-05-15',1);
    INSERT INTO Orders VALUES (4,2,'2013-05-14',3);
    INSERT INTO Orders VALUES (2,3,'2013-05-13',1);
    INSERT INTO Orders VALUES (2,4,'2013-05-12',1);
    

Adding the database from backup file

You can add the database to SQL Server from SQL-file or from bak-file.

Executing the SQL-file

Here is assumed that you have an sql-file(northwind.sql), which includes the code that is needed for creating the database.

      Create database Northwind

      Give the command in cmd:
      sqlcmd -S .\SQLEXPRESS  -d Northwind  -i northwind.sql\northwind.sql
    

Executing the Bak-file

You can create and execute the Bak-file from Management Studio. The file should be located on directory, which something like:C:\Program Files\Microsoft SQL Server\MSSQL14.SQLEXPRESS\MSSQL\Backup

You can add the database like this

  • You dont have to create the database
  • Right click Databases
  • Choose Restore database
  • Choose Device and click the button with ellipses
  • Click Add and choose the rigth bak-file
  • Click several times OK

Creating the Bak-file

You can create the file like this:

  • Right click the desired database (in Management Studio)
  • Choose Tasks->Backup
Now in folder ...MSSQL\Backup should exists the new bak-file.