CPS 430/542 Lecture notes: Defining and populating a relation schema in SQL

Coverage: [FCDB] §§6.5-6.6 (pp. 286-301)


  • various datatypes
  • setting primary key
  • adding and dropping attributes
  • default values (not null)
  • adding, dropping, and modifying tuples

Online guides

Basic tasks

  • creating a relation:
      CREATE TABLE Movies (title CHAR (22),
             year INTEGER, length INTEGER,
             stdio CHAR (32));
  • inserting a tuple into a relation: INSERT INTO Movies;
  • dropping a relation: DROP TABLE Movies;
    • need not be empty to drop
    • if not empty, all tuples lost
    • use with caution
    • maintain backups of your database


    [FCDB] J.D. Ullman and J. Widom. A First Course in Database Systems. Prentice Hall, Upper Saddle River, NJ, Second edition, 2002.

Return Home