|
| ||||||||||
| Tags: database, error message, mysql, primary key, sql |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| How to manage databases and tables in MySQL?
![]() |
|
#2
| |||
| |||
| Re: How to manage databases and tables in MySQL?
Let's start with the creation of a database: Code: CREATE DATABASE [IF NOT EXISTS] db_name [CHARACTER SET charset] [COLLATE collation] Code: ALTER DATABASE db_name [CHARACTER SET charset] [COLLATE collation] DROP DATABASE [IF EXISTS] db_nameThis is a statement as simple as potentially devastating to its implementation in fact erase all data in the database. It goes without saying that you must use extreme caution before using it, since the SQL language does not provide in any case, the request for confirmation. To run it you need the DROP privilege on the database. |
|
#3
| |||
| |||
| Re: How to manage databases and tables in MySQL?
The basic instruction to create a table is as follows: Code: CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(Definition ,...)] [Option ...] [select] |
|
#4
| ||||
| ||||
| Re: How to manage databases and tables in MySQL?
The definitions can be column definitions or definitions for the table. We see a column definition: Code: column_name type [NOT NULL | NULL] [DEFAULT value] [AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY] [COMMENT 'comment'] [reference_definition] Also I would like to warn you that this behavior was introduced with version 5.0.2 of MySQL, the first of which was always provided a default value (the default implicit type of column when not indicated). This is an important difference, because when entering data, if not stated value for a column that has no explicit default and is active strict_mode, an error is generated. |
|
#5
| ||||
| ||||
| Re: How to manage databases and tables in MySQL?
AUTO_INCREMENT can be used with a column of type integer to have a sequential value is automatically generated by the server for each inserted row in the table. For each table there can be only one AUTO_INCREMENT, the column must be indexed and can not have default. When entering you use NULL to ensure that the value is generated by MySQL. UNIQUE is an index that can not contain duplicate values, PRIMARY KEY is the primary key of the table and, in addition to not allow duplicates, may not contain NULL values. The "reference_definition" is a foreign key to another table, and this is its syntax: REFERENCES table_name [(column_index,...)]MySQL allows the use of foreign keys only on InnoDB tables (see lesson 8), but the syntax is also allowed on other types of tables (obviously without consequences). |
|
#6
| ||||
| ||||
| Re: How to manage databases and tables in MySQL?
Now let's see the other possible definitions (for the entire table): Code: [CONSTRAINT [symbol]] PRIMARY KEY [type_index] (column_index ,...) | KEY [index_name] [type_index] (column_index ,...) | INDEX [index_name] [type_index] (column_index ,...) | [CONSTRAINT [symbol]] UNIQUE [INDEX] [Index_name] [type_index] (column_index ,...) | [FULLTEXT | SPATIAL] [INDEX] [index_name] (column_index ,...) | [CONSTRAINT [symbol]] FOREIGN KEY [Index_name] (column_index ,...) [reference_definition] |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "How to manage databases and tables in MySQL?" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| MySQL: Entering data in tables | Botan | Software Development | 2 | 22-12-2010 04:44 AM |
| How to detect failure of MySQL database tables | Agneya | Software Development | 5 | 27-02-2010 03:40 AM |
| How to create MySQL Database and Tables in PHP? | Orton | Software Development | 4 | 23-02-2010 05:45 AM |
| Mysql select from multiple tables for php. | afidelino | Software Development | 4 | 09-07-2009 06:13 PM |
| Restore corrupted MyISAM/InnoDB tables on MySQL 5.0 | jean-paul martell | Software Development | 5 | 14-04-2009 09:03 AM |