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, 2020 in Azure by anonymous
• 19,610 points
37,600 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!

Hope this helps!!

To know more about Azure, enroll today with our Azure certification course.

Thanks!!

answered Jan 22, 2020 by Sirajul
• 59,230 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,640 points
1,235 views
0 votes
1 answer

How to query between databases in SQL Azure Database Server?

SQL Azure supports cross database queries: https://azure.microsoft.com/en-us/blog/querying-remote-databases-in-azure-sql-db/ Hope this ...READ MORE

answered Apr 9, 2019 in Azure by Prerna
• 1,960 points
12,997 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
2,628 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
2,620 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, 2020 in Azure by Sirajul
• 59,230 points
2,084 views
0 votes
1 answer

What are azure functions? What is their use?

Azure Functions is a serverless computing service hosted ...READ MORE

answered Jan 10, 2020 in Azure by Sirajul
• 59,230 points

edited Jun 27, 2023 by Khan Sarfaraz 2,011 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, 2020 in Azure by Sirajul
• 59,230 points
1,486 views
+1 vote
1 answer

How to backup Azure SQL Database?

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

answered Jan 22, 2020 in Azure by Sirajul
• 59,230 points
23,278 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP