How to create table in Azure SQL Database?

0 votes

I am using Azure SQL Database for my application. I already have created a single empty database and created a firewall to restrict access to it and also established connection to the database. Now I am stuck at a point where I have to create tables based on the schema containing four tables that represent a student management system for universities as shown in the figure.

Can somebody help me with the way forward? Thanks.

Jan 22 in Azure by anonymous
• 18,640 points
4,120 views

1 answer to this question.

0 votes

Creating tables in Azure SQL Database:

  • In Object Explorer, right-click yourDatabase and select New Query. A blank query window opens that is connected to your database.

  • In the query window, execute the following query to create four tables in your database:

-- Create Person table
CREATE TABLE Person
(
    PersonId INT IDENTITY PRIMARY KEY,
    FirstName NVARCHAR(128) NOT NULL,
    MiddelInitial NVARCHAR(10),
    LastName NVARCHAR(128) NOT NULL,
    DateOfBirth DATE NOT NULL
)

-- Create Student table
CREATE TABLE Student
(
    StudentId INT IDENTITY PRIMARY KEY,
    PersonId INT REFERENCES Person (PersonId),
    Email NVARCHAR(256)
)

-- Create Course table
CREATE TABLE Course
(
    CourseId INT IDENTITY PRIMARY KEY,
    Name NVARCHAR(50) NOT NULL,
    Teacher NVARCHAR(256) NOT NULL
)

-- Create Credit table
CREATE TABLE Credit
(
    StudentId INT REFERENCES Student (StudentId),
    CourseId INT REFERENCES Course (CourseId),
    Grade DECIMAL(5,2) CHECK (Grade <= 100.00),
    Attempt TINYINT,
    CONSTRAINT [UQ_studentgrades] UNIQUE CLUSTERED
    (
        StudentId, CourseId, Grade, Attempt
    )
)

  • Expand the Tables node under yourDatabase in the Object Explorer to see the tables you created.

You can see that the 4 tables are created successfully!

answered Jan 22 by Sirajul
• 58,130 points

Related Questions In Azure

0 votes
1 answer

How to calculate the used database space in SQL Azure?

I don't think its possible to find ...READ MORE

answered Mar 5, 2019 in Azure by Archana
• 5,600 points
127 views
0 votes
1 answer

How to query between databases in SQL Azure Database Server?

SQL Azure supports cross database queries: https://azure.micro ...READ MORE

answered Apr 9, 2019 in Azure by p
• 1,960 points
3,608 views
0 votes
1 answer

How to identify a deadlock in SQL Azure?

Monitoring of SQL Azure is more limited ...READ MORE

answered Jun 19, 2018 in Azure by club_seesharp
• 3,450 points
966 views
+1 vote
1 answer

How to copy Azure SQL database to a local development server?

Actually, there are multiple ways to do ...READ MORE

answered Jul 9, 2018 in Azure by null_void
• 3,220 points
872 views
0 votes
1 answer

How is Azure Cosmos db different from an Azure SQL db?

Azure Cosmos DB is Microsoft’s globally distributed database ...READ MORE

answered Jan 10 in Azure by Sirajul
• 58,130 points
696 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

What is Azure SQL database? How to connect to Azure SQL database?

Azure SQL Database is a general-purpose relational ...READ MORE

answered Jan 13 in Azure by Sirajul
• 58,130 points
301 views
+1 vote
1 answer

How to backup Azure SQL Database?

In Azure SQL Database, you can configure ...READ MORE

answered Jan 22 in Azure by Sirajul
• 58,130 points
7,197 views