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

Oracle SQL Tutorial 11 - CREATE TABLE

214 ratings | 27878 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 (20)
Mohammed Umar (4 months ago)
Thanks for your videos.. learning database was never this fun
MOGAHID AHMED (7 months ago)
if I change "varchar2" to " text"
Piyush Bhedurkar (8 months ago)
hi, does it is important to form different table for entities from EER model.
listommania 85 (9 months ago)
You are very good at teaching and catching my attention, thank you.
كايو تشان (11 months ago)
Rajib Kumar Halder (1 year ago)
How To CREATE TABLE using graphical interface in oracle 12c
Fatal Tiberious (1 year ago)
one of the biggest things that i find different answers too is whether holding href files within an sql db is better for security or just making php files that are secure at the server and use passwords instead .have you got any feedback on that at all thanks
warnage sasith (1 year ago)
nice job bro!!
Rafsan Hossain (1 year 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 (1 year ago)
Thanks for all these great videos. Well done!
zahra athari (1 year 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 (6 months ago)
You need to confirm your account through your email for verification
Caleb Curry (1 year 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 (1 year ago)
http://stackoverflow.com/questions/1171196/what-is-the-difference-between-varchar-and-varchar2 This is the answer for using 'VARCHAR2'
tandin gyeltshen (1 year ago)
is this tutorial for oracle 11g or 10
Caleb Curry (1 year ago)
11g +
Elijah Ducote (1 year 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 (1 year ago)
No problem!
Elijah Ducote (1 year ago)
+CalebTheVideoMaker2 Thanks, that's really helpful. :)
Caleb Curry (1 year 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.