How do you create a table? How do you define the schema for a table? How do you define the parameters of the columns in a table? Learn the answers to these questions in this video.
- [Instructor] Tables are created with the "Create Table" statement. Here we're using the test database. We have some SQL statements here that are copied and pasted from the Chapter Three exercise file. You'll notice that this is a create table statement, and you'll notice that it's spread out over several lines. That the semicolon ends the statement, and the statement begins with the "Create Table" keywords. So this creates a simple table. "Create Table" statements are normally formatted like this, such that the column declarations are each on a line by themselves. This makes it easier to read, but does not affect the functionality. So all of this could be on one line, and it would work exactly the same. The "Create Table" statement creates a table according to the provided parameters. The column definitions are sometimes called the database schema or the table schema. So the part between the parentheses is this schema. The syntax is pretty simple, each column definition starts with the column name, in this case A and B, and is followed by the type declaration. So here we have an integer and here we have a text column. And these are separated by commas, but you'll notice that the last item cannot have a comma. Actually, a comma here is a syntax error. You notice that stuff after it starts turning red. You cannot have a comma after the final item in the list of columns. And then there's a close parenthesis and a terminating semicolon. So if I go ahead and execute this like I will here, pressing F9 to execute that, you notice that this creates a table here in the test database. And so here we have the table test, it has two columns, A and B. And if we open this up, we see there's two columns and they are A and B. So at this point, there's no data in this table. So if I execute this select statement, you'll notice that I don't get any results in here, I get two empty, I get the column titles, but I don't get any rows, they're empty. So if I execute all four of these lines, I have "Insert Into", so this'll insert three rows, and then the select statement. And if I go ahead and press F9 now, you'll notice that I get these three rows, one, two, three, and A, B, C, according to what I inserted into those rows. So a "Create Table" statement is used to create a table with a particular schema. You'll use this when designing and declaring your database tables. We're going to leave this table here for the next lesson.
This course was created by Bill Weinman. We are pleased to offer this training in our library.
- How databases are organized
- Selecting rows and columns
- Creating new tables
- Inserting and updating data
- Sorting and filtering
- Accessing related tables with JOIN
- Working with strings
- Understanding numeric types
- Using aggregate functions and transactions
- Automating data with triggers
- Creating views
- Using CRUD functions
Skill Level Beginner
2. SQL Overview
3. Fundamental Concepts
7. Dates and Times
Dates and times2m 6s
11. Views and Subselects
12. A Simple CRUD Application
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.