-4

I am new to MySQL and I created a table, but I am not exactly sure what is going on.
I have these lines:

mysql> CREATE TABLE tutorials_tbl(
   -> tutorial_id INT NOT NULL AUTO_INCREMENT,
   -> tutorial_title VARCHAR(100) NOT NULL,
   -> tutorial_author VARCHAR(40) NOT NULL,
   -> submission_date DATE,
   -> PRIMARY KEY ( tutorial_id )
   -> );

Obviously CREATE TABLE tutorials_tbl creates a table named tutorials_tbl, but what is the purpose of the other lines?

user3771865
  • 11
  • 1
  • 1
  • 7

3 Answers3

0

The other lines define the columns in the table and a key (index) for looking up rows by unique values in tutorial_id. You should read about CREATE TABLE in the docs.

elixenide
  • 44,308
  • 16
  • 74
  • 100
  • so VARCHAR(100) NOT NULL -- what does this accomplish? – user3771865 Jul 09 '14 at 18:01
  • That is a column that can hold up to 100 characters (a string, like `foo bar`) and cannot be NULL. The `VARCHAR` column only takes as much storage space as it needs, unlike `CHAR`, which always takes the amount of space specified, even if the contents are shorter. – elixenide Jul 09 '14 at 18:02
0

The other lines are used for columns which includes their names, their datatypes, their size and some constraints applied to them

SparkOn
  • 8,806
  • 4
  • 29
  • 34
0

Well Other lines are the table columns, data types and the constraint

mysql> CREATE TABLE tutorials_tbl(
-> tutorial_id INT NOT NULL AUTO_INCREMENT, ... This line creates a column with an integer data type (that's numbers) which must always have a have a value it at all times(not null) and when you insert data in other columns it automatically insert in the column in a sequence ..1...2...3.
-> tutorial_title VARCHAR(100) NOT NULL,... creates a column with a Variable Character type with maximum length of 100. So you can only store a maximum length of 100 characters inside
-> tutorial_author VARCHAR(40) NOT NULL,.. same as above with max length of 40 and cannot be empty
-> submission_date DATE,.. another colume with a data data type. can only contain a date format content
-> PRIMARY KEY ( tutorial_id ) you enforcing a primary key constraint to make sure that no duplicate values are stored in the tutorial_id
-> );
gmo
  • 8,860
  • 3
  • 40
  • 51
Softwarex3
  • 33
  • 1
  • 1
  • 7