Oracle SQL Tutorial 11 - CREATE TABLE

submitted by mkenny400 on 03/23/18 1

The way you create a table is to use the CREATE TABLE command. CREATE TABLE users() So in this situation, the name comes right after the TABLE keyword. The next thing we do is put all of the columns on a line that we want to put in our table. CREATE TABLE users( user_id, username, first_name, last_name ) Notice the naming conventions here. For this series we are going to make columns with what is known as snake casing. This is where each individual word is separated by an underscore. if you have more than one column, all of them have to have commas except the last one. The comma is a way to say that another column is coming, so you don't need to do it on the last one. Now you would think we were done, but we also have to say what data type each column is. Later we will extensively discuss data types so we can focus on them exclusively. For now, here are the data types we are going to use: CREATE TABLE users( user_id NUMBER, username VARCHAR2(50), first_name VARCHAR2(50), last_name VARCHAR2(50) ) Now, inside of the parenthesis for varchar2, we pass in a number... This is the max length of the string. But the question is, what is it measured in? The default is actually in bytes, not characters. For example if we have the string hello, it is 5 characters, but it might take up a total of 10 bytes of storage. So I would recommend adding the keyword char right after the number so it defaults to 50 characters, not bytes. CREATE TABLE users( user_id NUMBER, username VARCHAR(50 CHAR), first_name VARCHAR2(50 CHAR), last_name VARCHAR2(50 CHAR) ) This will work to create a table, but it's really missing a lot of information… which column is the primary key? Are we adding any indexes? Is there any thing else we need to say about these columns? So as you can tell, we are making progress, but there is still so much to learn. The biggest gotcha to remember from this video is that the data type VARCHAR ends in a 2, stupid, right? who would end the name of something with a 2? Once again, this is Caleb from CalebTheVideoMaker2, and we will catch you in the next one! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HELP ME! www.patreon.com/calebcurry Subscribe to my newsletter: eepurl.com/-8qtH Donate!: bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: CalebCurry.com Facebook: www.facebook.com/CalebTheVideoMaker Google+: plus.google.com/+CalebTheVideoMaker2 Twitter: twitter.com/calebCurry Amazing Web Hosting - www.dreamhost.com/r.cgi?1487063 (The best web hosting for a cheap price!)

Leave a comment

Be the first to comment

Collections with this video
Email
Message
×
Embed video on a website or blog
Width
px
Height
px
×
Join Huzzaz
Start collecting all your favorite videos
×
Log in
Join Huzzaz

facebook login
×
Retrieve username and password
Name
Enter your email address to retrieve your username and password
(Check your spam folder if you don't find it in your inbox)

×