Question

Write SQL to create a table called City in your account. The schema of the table...

Write SQL to create a table called City in your account. The schema of the table is listed below. You must define the data types and not null constraint (if needed) of every column and all the primary key and foreign key constraints for the table. No screenshot needed for this question.

City (Name, Country, Population, Capital).
Name: the name of the city. Text string with maximum 50 characters. Must not be null.

Country: the name of the country where this city belongs to. It is a foreign key referencing the name column of the country table. Could be null.

Population: integer with up to 11 digits. Population of the city. Could be null.
Capital: one character (fixed length). ‘Y’ for capital cities and ‘N’ otherwise. Could be null.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Query to create the city table

CREATE TABLE city (

   Name varchar2(50) primary key,

   Country varchar2(60),

   population number(11,0),

   capital char(1),

   check (capital ='Y' or capital ='N' or capital= null),

   FOREIGN KEY (Country) REFERENCES country(name)

);

Add a comment
Know the answer?
Add Answer to:
Write SQL to create a table called City in your account. The schema of the table...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Utilize the JigSaw SQL file below to create a Star Schema diagram. Remember, to create a...

    Utilize the JigSaw SQL file below to create a Star Schema diagram. Remember, to create a Star Schema from a normalized data model, you will need to denormalize the data model into fact and dimension tables. The diagram should contain all of the facts and dimension tables necessary to integrate the JigSaw operational database into a data warehouse. Write a brief paper describing the challenges you experienced in completing this assignment. -- CREATE DATABASE js; CREATE TABLE buy_methods ( buy_code...

  • Q12. (12 pts) Write SQL statements to insert the following 3 cities as well as your...

    Q12. (12 pts) Write SQL statements to insert the following 3 cities as well as your home city into the city table. If your home city is already listed, then add a different city you have visited. Leave the Population column of the last city empty. If your home country is not listed in the country table, you may also leave the Country column empty and add a comment in your SQL script file to explain this. Then write a...

  • (SQL) Write DDL statements to create the tables below and use appropriate data types for the...

    (SQL) Write DDL statements to create the tables below and use appropriate data types for the attributes.Relational database schema: Teacher = [CourseN, Quarter,TeacherName] Course = [CourseN,CourseName, Nunit) LocationNTime = [CourseN, Quarter , DayTime, RoomN] . //Examples of DayTime: M2:00AM, W4:50PM, and T8:00PM. Note that DayTime is represented as a string. Student = [studentName, CourseN, Quarter] .................... The DDL statement must include at least the following constraints: Every Primary Key; Every Foreign Key; For every Foreign Key constraint, the referential integrity...

  • Create a T-SQL statement that creates a table called Owner as part of a schema called...

    Create a T-SQL statement that creates a table called Owner as part of a schema called PetStore. Create the table to have 2 columns with the following criteria: Column OwnerID of type int. Make this column an IDENTITY column starting with seed 1 and incrementing by 1 Column OwnerName of type varchar and length 50, not null

  • -- Schema definition create table Customer (     cid   smallint not null,     name varchar(20),    ...

    -- Schema definition create table Customer (     cid   smallint not null,     name varchar(20),     city varchar(15),     constraint customer_pk         primary key (cid) ); create table Club (     club varchar(15) not null,     desc varchar(50),     constraint club_pk         primary key (club) ); create table Member (     club varchar(15) not null,     cid   smallint     not null,     constraint member_pk         primary key (club, cid),     constraint mem_fk_club         foreign key (club) references Club,     constraint mem_fk_cust...

  • SQL Command - Create a view called S LIST that lists the Cardholder Number, last name,...

    SQL Command - Create a view called S LIST that lists the Cardholder Number, last name, first name and due date for all cardholders who have not returned a book. Use the CREATE OR REPLACE VIEW AS ... command. TABLE CARD HOLDERS Cardholder Numberint NOT NULL CONSTRAINT CH PK PRIMARY KEY, First_Name varchar(10) NULL, LastName varchar(15) NULL, Address varchar(20) NULL, varchar(15) NULL, State char(2) NULL, Zip_Code char(5) NULL) City TABLE BOOKS CHECKED OUT Cardholder_Numberint NOT NULL, Book Numberint NOT NULL,...

  • SQL CHECK CONSTRAINT AND TEST CASE... SQL Query Here are the tables: CREATE TABLE Movies(     movieID...

    SQL CHECK CONSTRAINT AND TEST CASE... SQL Query Here are the tables: CREATE TABLE Movies(     movieID INT,     name VARCHAR(30) NOT NULL,     year INT,     rating CHAR(1),     length INT,     totalEarned NUMERIC(7,2),     PRIMARY KEY(movieID),     UNIQUE(name, year) ); CREATE TABLE Showings(     theaterID INT,     showingDate DATE,     startTime TIME,     movieID INT,     priceCode CHAR(1),     PRIMARY KEY(theaterID, showingDate, startTime),     FOREIGN KEY(theaterID) REFERENCES Theaters,     FOREIGN KEY(movieID) REFERENCES Movies ); CREATE TABLE Tickets(     theaterID INT,     seatNum INT,     showingDate DATE,     startTime TIME,     customerID INT,     ticketPrice NUMERIC(4,2),     PRIMARY KEY(theaterID, seatNum, showingDate, startTime)...

  • Q.1] Write SQL statements based on the tennis database schema (practice homework 5) Get all the different tow...

    Q.1] Write SQL statements based on the tennis database schema (practice homework 5) Get all the different town names from the PLAYERS table. 2. For each town, find the number of players. 3. For each team, get the team number, the number of matches that has been played 'for that team, and the total number of sets won. 4. For each team that is captained by a player resident in "Eltham", get the team number and the number of matches...

  • Write a single SQL statement to create a new playlist called 'Background music'; and write another...

    Write a single SQL statement to create a new playlist called 'Background music'; and write another single SQL statement to associate the new playlist with the 10 longest duration tracks of jazz music from the Track table. CREATE TABLE MediaType ( MediaTypeID INTEGER PRIMARY KEY NOT NULL, Name TEXT ); CREATE TABLE Playlist ( PlaylistID INTEGER PRIMARY KEY NOT NULL, Name TEXT ); CREATE TABLE PlaylistTrack ( PlaylistID INTEGER NOT NULL, TrackID INTEGER NOT NULL, PRIMARY KEY (PlaylistID, TrackID), FOREIGN...

  • SQL Query Question: I have a database with the tables below, data has also been aded...

    SQL Query Question: I have a database with the tables below, data has also been aded into these tables, I have 2 tasks: 1. Add a column to a relational table POSITIONS to store information about the total number of skills needed by each advertised position. A name of the column is up to you. Assume that no more than 9 skills are needed for each position. Next, use a single UPDATE statement to set the values in the new...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT