Question:
MySQL: Creating a table, what do these Columns mean?
jumpingrightin
2010-05-20 12:55:03 UTC
I'm creating a MySQL table and I'm not clear on what these Columns defined in MySQL are really for and how they are used:
After Field, there is Type, Null, Key, Default, Extra.
What does the Null Columbus do? Especially when I see the Default is NULL, but the Null Columns is set to NO.

+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
Four answers:
D Bügger™
2010-05-20 14:40:41 UTC
1)Field:-in database terminology the rows are called Fields so row name is denoted by field as id,name,age etc.



2)Type:-defines the data type of the field as integer,character,date etc



3)Null:-no: specifies that the value cannot be null (empty). that is, each row in the column would have a value.As id cannot be null so it has been assigned as NOT NULL



4)KEY:-key can be primary(PRI),FOREIGN etc. no two data entries can be same for the id since it is primary key and uniquely identifies each row.A primary key of another table is foreign key.



5)DEFAULT:Here some default value should have been passed for the id because primary key cannot be null.if default is set to null it means it has no value.So while creating an id field following comand should be passed:-

id int unsigned not null auto_increment primary key



6)EXTRA :-extra property is set to auto increment so when MySQl comes across a column with an auto_increment attribute, it generates a new value that is one greater than the largest value in the column. Thus, we don't need to supply values for this column, MySQL generates it for us! Also, it follows that each value in this column would be unique.



Refer to database system concepts by Korth (McGraw Hill) for understanding of field and its attributes .
Ashy
2010-05-20 20:05:05 UTC
So it is a table, with

Field: id -- just a name

Type: int(11) -- the value has to be a number (11 digits or less)

Null: Is the value null or not

Key: I am not sure

Default: the default is null but since auto-increment is set, it will be filled in automatically anyway with every insert
DanielDude
2010-05-20 20:02:55 UTC
as far as I know Type is what type of value you want (integer (which is numbers) dates (numbers used as dates), string (letters and numbers), etc.)

Null is useless (it makes the value nothing),

Key is like an order of values (eg. name = 1, age = 2, etc.)

Default is if you don´t set it, it will be this.

Extra is extra stuff you can do (auto_increment is when you upload a new cell and don´t set this it will automatically increment (1, 2, 3, 4, etc).
Neunerball
2010-05-20 20:57:26 UTC
In general, that's how the syntax for a SQL-command in MySQL is described.

For learning SQL go to the following link http://www.w3schools.com/Sql/sql_intro.asp


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...