๐ก
This is the series where I try to solve The Top 100 SQL problems from the Coding Ninja website.
Problem Statement
The problem statement is:
You are given a list of movies and their ratings from IMDb, a popular movie database website.
You're asked to Insert below student details below in the student table and print all data from the table Using SQL.
Here is the detail you need to add.
ID | Name | Gender |
3 | Kim | F |
4 | Molina | F |
5 | Dev | M |
Dataset
CodingNinja gives us the .sql script to create a table named "students"
The Script
This is the given script.
CREATE TABLE IF NOT EXISTS students (
id numeric ,
name text NOT NULL,
gender text NOT NULL,
PRIMARY KEY(id)
);
-- insert some values
INSERT INTO students VALUES (1, 'Ryan', 'M');
INSERT INTO students VALUES (2, 'Joanna', 'F');
However, this script didn't execute on sql server.
Here is the working script.
IF OBJECT_ID(N'dbo.students', N'U') IS NOT NULL
DROP TABLE dbo.students;
CREATE TABLE students (
id INT PRIMARY KEY, -- numeric primary key
name VARCHAR(50) NOT NULL, -- text column
gender VARCHAR(10) -- text column
)
INSERT INTO students (id, name, gender)
VALUES
(1, 'Ryan', 'M'),
(2, 'Joanna', 'F');
this will drop any table named "students" and create a new table.
Add new raws
This part will add 3 new raws given in the problem statement.
INSERT INTO students (id, name, gender)
VALUES
(3, 'Kim', 'F'),
(4, 'Molina', 'F'),
(5, 'Dev', 'M');Earning
Final results table
Full script Here.
ย