diff --git a/soitool/database.py b/soitool/database.py
index fc2289c2add8cf185c9e31817938319015bad7e8..11de13ed33669c32bd4f1fb5acc89580ebf24519 100644
--- a/soitool/database.py
+++ b/soitool/database.py
@@ -11,7 +11,7 @@ DBPATH = os.path.join(CURDIR, DBNAME)
 # DDL-statements for creating tables
 CODEBOOK = 'CREATE TABLE CodeBook' \
            '(Word VARCHAR PRIMARY KEY, Category VARCHAR,' \
-           ' Type int DEFAULT 0, Code VARCHAR)'
+           ' Type int DEFAULT 0, Code VARCHAR UNIQUE)'
 CATEGORYWORDS = 'CREATE TABLE CategoryWords' \
                 '(Word VARCHAR PRIMARY KEY, Category VARCHAR)'
 BYHEART = 'CREATE TABLE ByHeart(Word VARCHAR PRIMARY KEY)'
diff --git a/soitool/main_window.py b/soitool/main_window.py
index b0deab03e6dcc3a2eb2f6c9b290f2d3c0d6d95df..a1bb93f2249aec9512277183ec99187a25f8cd03 100644
--- a/soitool/main_window.py
+++ b/soitool/main_window.py
@@ -6,14 +6,16 @@ out to separate modules.
 """
 import sys
 import os
+from functools import partial
 from PySide2.QtCore import QRectF, QPoint, QTimer, Qt, QUrl
 from PySide2.QtWidgets import QTabWidget, QWidget, QMainWindow, \
     QApplication, QHBoxLayout, QVBoxLayout, QPushButton, QLabel, \
-    QAbstractItemView, QListWidget, QListWidgetItem, QAction, QGraphicsScene, \
-    QGraphicsView, QScrollArea, QGraphicsRectItem
+    QAbstractItemView, QListWidget, QListWidgetItem, QAction, \
+    QGraphicsScene, QGraphicsView, QScrollArea, QGraphicsRectItem
 from PySide2.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings
 from PySide2.QtGui import QBrush, QIcon, QPalette, QFont, QPixmap
 from soitool.modules.module_table import TableModule
+from soitool.codebook import CodeBookTableView
 
 
 class MainWindow(QMainWindow):
@@ -72,11 +74,13 @@ class MainWindow(QMainWindow):
         # Small codebook
         small_codebook = QAction("Liten kodebok", self)
         small_codebook.setStatusTip("Vis liten kodebok")
+        small_codebook.triggered.connect(partial(self.open_codebook_tab, True))
         codebook.addAction(small_codebook)
 
         # Big codebook
         big_codebook = QAction("Stor kodebok", self)
         big_codebook.setStatusTip("Vis stor kodebok")
+        big_codebook.triggered.connect(partial(self.open_codebook_tab, False))
         codebook.addAction(big_codebook)
 
         # Hot keys
@@ -90,11 +94,11 @@ class MainWindow(QMainWindow):
         help_menu.addAction(easy_use)
 
         # Legger til MainWidget som en tab, kanskje flytt ut til egen funksjon
-        tabs = QTabWidget()
+        self.tabs = QTabWidget()
         tab = SOIWorkspaceWidget()
 
-        tabs.addTab(tab, "MainTab")
-        self.setCentralWidget(tabs)
+        self.tabs.addTab(tab, "MainTab")
+        self.setCentralWidget(self.tabs)
 
         # Add HV logo
         filename = 'media/HVlogo.PNG'
@@ -102,6 +106,23 @@ class MainWindow(QMainWindow):
         filepath = os.path.join(dirname, filename)
         self.setWindowIcon(QIcon(filepath))
 
+    def open_codebook_tab(self, is_small):
+        """Open and selects tab containing CodeBookTableView.
+
+        Parameters
+        ----------
+        is_small : bool
+            The view shows small codebook if True, entire codebook otherwise.
+        """
+        # If not any other codebook-tab:
+        # # QSqlDb merker ekstra connection og fjerner den gamle når ny åpnes
+        tab = CodeBookTableView(is_small)
+        if is_small:
+            self.tabs.addTab(tab, 'Liten Kodebok')
+        else:
+            self.tabs.addTab(tab, 'Stor kodebok')
+        self.tabs.setCurrentWidget(tab)
+
 
 class SOIWorkspaceWidget(QWidget):
     """Contains the working area for a single SOI.