slug
type
status
category
summary
date
tags
password
icon
Let's go through the steps to create a database, create a table with various data types, and alter the table to add primary and foreign keys. I'll use SQL syntax for these tasks.

1. Create a Database

2. Create a Table with Various Data Types

3. Alter Table to Add a Foreign Key

Assuming we have another table Courses with a primary key CourseID, we will add a foreign key CourseID to the Students table.
First, let's create the Courses table:
Next, we alter the Students table to add a foreign key:

Complete SQL Script

Here's the complete script combining all the above steps:
This script will:
  1. Create a database named SchoolDB.
  1. Create a Students table with various data types and a primary key on StudentID.
  1. Create a Courses table with a primary key on CourseID.
  1. Alter the Students table to add a CourseID column and a foreign key constraint linking it to the CourseID column in the Courses table.
8a Introduction to Databases8c How to modify a database
Loading...