DBMS and RDBMS blunders

Hello, I hope you are having a fantastic day. I’m presently learning about Database Management Systems (DBMS) and Relational Database Management Systems (RDBMS), however I’ve run into a few challenges while dealing with SQL. I’m reaching out to ask for your help in conquering these obstacles.

Here’s a bit of the SQL code I’ve been working with:

-- Creating a table in an RDBMS
CREATE TABLE Employee
    EmployeeID INT PRIMARY KEY,
    FirstName VARCHAR(50),
    LastName VARCHAR(50),
    Department VARCHAR(50);

In this SQL code sample, I’ve noticed four difficulties that I’m attempting to solve:

1.The CREATE TABLE statement appears to have a syntax issue. Can you help me find and rectify the syntax mistake that prevented me from correctly creating the “Employee” table?
2.While attempting to specify the primary key for the “Employee” table, I received an error message stating “missing ‘(’ after ‘PRIMARY’”. How can I fix this problem and correctly declare the main key?
3.The data types for the columns “FirstName,” “LastName,” and “Department” are defined, but I’m not sure whether they’re suitable. Could you please advise on picking acceptable data types for these columns?
4.I added semicolons at the end of each line, but I’m not sure if this is essential or if it would cause problems. As shown in that source, Should semicolons be used in this situation, and if not, what is the proper approach?

Your comments and knowledge would be highly welcomed as I face these problems. Thank you for your help.

What source do you use to learn SQL - I mean other than this forum?
Each source should provide working samples. The good ones actually explain how to build the correct syntax. There are literally dozens of websites that will answer your questions.
Try Intro to SQL: Querying and managing data | Khan Academy

  1. enclose everything between the tablename and the semicolon in parenthesis
  2. you attempt a RDBMS-specific syntax (meaning not part of SQL standard) to specify the primary key. The standard calls for the keyword primary key followed by a list of columns that make up the primary key enclosed in parenthesis (e.g. PRIMARY KEY (EmployeeID))
  3. Is this an exam question? These types are fine in real world use. In an exam you should look for a more specific data type from the list of data types that were taught.
  4. Semicolons are a common way to indicate the end of a SQL statement. Some RDMSs use different keywords. Most famously SQL Server prefers GO (but in recent versions accepts semicolons, too).
1 Like

Just to nitpick a bit, SQL Server has always accepted “;” as a statement terminator (at least since SQL 2000ish) but hasn’t ever enforced it as a requirement.

GO in SQL Server is a batch separator, and actually you can override it to be a different word if you like.

3 Likes