HomeНаука и техникаRelated VideosMore From: Caleb Curry

Oracle SQL Tutorial 11 - CREATE TABLE

303 ratings | 39034 views
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! http://www.patreon.com/calebcurry Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter Donate!: http://bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: http://CalebCurry.com Facebook: http://www.facebook.com/CalebTheVideoMaker Google+: https://plus.google.com/+CalebTheVideoMaker2 Twitter: http://twitter.com/calebCurry Amazing Web Hosting - http://bit.ly/ccbluehost (The best web hosting for a cheap price!)
Html code for embedding videos on your blog
Text Comments (23)
Thomas (2 months ago)
can you please post the exact link for downloading that particular vesion of oracle?
A C (3 months ago)
itsurguy1 (4 months ago)
Hello Caleb Thank you for the video about creating tables. However, can you create a video that shows how to create a table based on a paragraph from a client so we can actually see how to look at a paragraph and select the primary keys, attributes and foreign keys that is needed to create the table. It's good to know how to create the table but creating the table from a paragraph or upgrading a table is the difficult part I believe because you have to know what the user wants and not create data redundancy or violate the Armstrong Axiom also normalization and relational algebra. Help us out brotha. Every other video on youtube on this subject seems like its from India all the time and the accent is terrible. We don't even know if they are teaching the correct way to build a database
Mohammed Umar (9 months ago)
Thanks for your videos.. learning database was never this fun
MOGAHID AHMED (1 year ago)
if I change "varchar2" to " text"
Piyush Bhedurkar (1 year ago)
hi, does it is important to form different table for entities from EER model.
listommania 85 (1 year ago)
You are very good at teaching and catching my attention, thank you.
كايو تشان (1 year ago)
Rajib Kumar Halder (1 year ago)
How To CREATE TABLE using graphical interface in oracle 12c
warnage sasith (2 years ago)
nice job bro!!
Rafsan Hossain (2 years ago)
VARCHAR is reserved by Oracle to support distinction between NULL and empty string in future, as ANSI standard prescribes.VARCHAR2 does not distinguish between a NULL and empty string, and never will.If you rely on empty string and NULL being the same thing, you should use VARCHAR2. (StackOverflow)
Alex S (2 years ago)
Thanks for all these great videos. Well done!
zahra athari (2 years ago)
hello sir, I have created an acount for installing oracle but i can not sign in i dont know wt the reason
Abdallah Kalolo (1 year ago)
You need to confirm your account through your email for verification
Caleb Curry (2 years ago)
I don't think you need to create an account. Check out the video in the beginning of this series on how to install Oracle.
Soumya Kanti Naskar (2 years ago)
http://stackoverflow.com/questions/1171196/what-is-the-difference-between-varchar-and-varchar2 This is the answer for using 'VARCHAR2'
tandin gyeltshen (2 years ago)
is this tutorial for oracle 11g or 10
Caleb Curry (2 years ago)
11g +
Elijah Ducote (2 years ago)
For the *CREATE TABLE* keyword, can we only make use of the following: name_id, username, first_name, etc. Or do we create our own unique ones?
Caleb Curry (2 years ago)
No problem!
Elijah Ducote (2 years ago)
+CalebTheVideoMaker2 Thanks, that's really helpful. :)
Caleb Curry (2 years ago)
You are able to put whatever columns that you want. The distinction between lower case and upper case helps us determine which things are keywords, and which things are made by us. The user_id is a column that I decided to make. I could have just as easily added a column such as birthdate, birthday, or age. By convention, every column is given an ID if we are using surrogate primary keys (in this case, we are). That means we will tell the database that it can generate a number for us for each row that has no real world meaning (outside of the database, that is).

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.