473,748 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

syntax problem for CREATE TABLE ??

Hi,

I was playing with MySQL (4.1.9) during the weekend, but noticed a minor
problem and would like someone to explain this to me.

Basically I could successfully create a table with one unique column
like this:

mysql> create table t1 (c1 int unique);
Query OK, 0 rows affected (0.08 sec)

What bothers me is that I just don't see how the CREATE TABLE syntax
allows the UNIQUE keyword to appear in a COLUMN_DEFINITI ON:

COLUMN_DEFINITI ON:
COL_NAME TYPE [NOT NULL | NULL] [DEFAULT DEFAULT_VALUE]
[AUTO_INCREMENT] [[PRIMARY] KEY] [COMMENT 'STRING']
[REFERENCE_DEFIN ITION]

The only explanation I can think of is that this way of declaring a
column unique was supported in some old release and the current version
of MySQL is just trying to keep the backwards compatibility (like SERIAL
column data type).

Does anyone know the real reason? Any input will be appreciated!

- Baoqiu

--
Baoqiu Cui <cbaoqiu at yahoo.com>
Jul 23 '05 #1
4 2311
Baoqiu Cui wrote:
What bothers me is that I just don't see how the CREATE TABLE syntax
allows the UNIQUE keyword to appear in a COLUMN_DEFINITI ON:

COLUMN_DEFINITI ON:
COL_NAME TYPE [NOT NULL | NULL] [DEFAULT DEFAULT_VALUE]
[AUTO_INCREMENT] [[PRIMARY] KEY] [COMMENT 'STRING']
[REFERENCE_DEFIN ITION]


You seem to have copied only the lower part of the definition. Read it
all and you should find the UNIQUE also:

http://dev.mysql.com/doc/mysql/en/create-table.html

------------------------
create_definiti on:
column_definiti on
| [CONSTRAINT [symbol]] PRIMARY KEY [index_type] (index_col_name ,...)
| KEY [index_name] [index_type] (index_col_name ,...)
| INDEX [index_name] [index_type] (index_col_name ,...)
| [CONSTRAINT [symbol]] UNIQUE[INDEX]
[index_name] [index_type] (index_col_name ,...)
| [FULLTEXT|SPATIA L] [INDEX] [index_name] (index_col_name ,...)
| [CONSTRAINT [symbol]] FOREIGN KEY
[index_name] (index_col_name ,...) [reference_defin ition]
| CHECK (expr)
column_definiti on:
col_name type [NOT NULL | NULL] [DEFAULT default_value]
[AUTO_INCREMENT] [[PRIMARY] KEY] [COMMENT 'string']
[reference_defin ition]
------------------------
Jul 23 '05 #2
Baoqiu Cui wrote:
mysql> create table t1 (c1 int unique);
Query OK, 0 rows affected (0.08 sec)

What bothers me is that I just don't see how the CREATE TABLE syntax
allows the UNIQUE keyword to appear in a COLUMN_DEFINITI ON:


It could just be an omission from the documentation. On the doc page
for create table, I find this paragraph:

"From MySQL 4.1.0 on, the attribute SERIAL can be used as an alias for
BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE."

That sort of implies that UNIQUE can appear in that position, similar to
PRIMARY KEY.

Regards,
Bill K.
Jul 23 '05 #3
Aggro <sp**********@y ahoo.com> writes:
Baoqiu Cui wrote:
What bothers me is that I just don't see how the CREATE TABLE syntax
allows the UNIQUE keyword to appear in a COLUMN_DEFINITI ON:
COLUMN_DEFINITI ON:
COL_NAME TYPE [NOT NULL | NULL] [DEFAULT DEFAULT_VALUE]
[AUTO_INCREMENT] [[PRIMARY] KEY] [COMMENT 'STRING']
[REFERENCE_DEFIN ITION]


You seem to have copied only the lower part of the definition. Read it
all and you should find the UNIQUE also:

http://dev.mysql.com/doc/mysql/en/create-table.html


The first part, which contains UNIQUE, is NOT for a COLUMN_DEFINITI ON.
I know I can do the following CREATE TABLE:

mysql> create table t1 (c1 int, unique (c1));
Query OK, 0 rows affected (0.06 sec)

but it is different from "create table t1 (c1 int unique)". I want to
find the syntax to allow the latter.

--
Baoqiu Cui <cbaoqiu at yahoo.com>
Jul 23 '05 #4
Bill Karwin <bi**@karwin.co m> writes:
It could just be an omission from the documentation. On the doc page
for create table, I find this paragraph:

"From MySQL 4.1.0 on, the attribute SERIAL can be used as an alias for
BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE."

That sort of implies that UNIQUE can appear in that position, similar
to PRIMARY KEY.


That is what I thought. Maybe the CREATE TABLE syntax should be changed
to explicitly allow UNIQUE in COLUMN_DEFINITI ON, because many people
(and many exiting MySQL examples) are using UNIQUE in this way.

--
Baoqiu Cui <cbaoqiu at yahoo.com>
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1902
by: konsu | last post by:
hello, would the experts please help. this script works with no errors: ------------------------------- drop table if exists degree; create table degree (id int unsigned not null auto_increment, primary key (id)) type=MyISAM; drop table if exists t;
1
4461
by: Jarrod Morrison | last post by:
Hi All Im still pretty new to using stored procedures and am not sure what syntax i should be using. The variable @LocationID will be something along the lines of 002, 003 and so on. What i want to do in the procedure is see if the table already exists, and if so delete it (The code i have only works if there is a record in the table). My problem with the syntax is that i want to combine the word "Location" with the @LocationID variable...
8
3351
by: Jan van Veldhuizen | last post by:
The UPDATE table FROM syntax is not supported by Oracle. I am looking for a syntax that is understood by both Oracle and SqlServer. Example: Table1: id name city city_id 1 john newyork null
3
2512
by: J West | last post by:
Warning: Error while executing this query:CREATE TABLE "purchaseorder" ( "PurchaseOrderID" int(10) unsigned NOT NULL auto_increment, "PurchaseCost" double unsigned zerofill NOT NULL default '0000000000000000000000', "PurchaseDescription" varchar(255) character set latin1 collate latin1_bin NOT NULL default '', "PurchaseeBayReference" varchar(45) default NULL, "PurchaseNotes" varchar(255) NOT NULL default '', "PurchasePicture" mediumblob...
3
6166
by: teddysnips | last post by:
In the script below is the DDL to create some tables and a UDF. What I'm interested in is the UDF at the end. Specifically, these few lines: --CLOSE OTRate --DEALLOCATE OTRate ELSE -- @NumRecords <= 0 If I uncommment CLOSE and DEALLOCATE and check the syntax I get a
8
4336
by: tom | last post by:
I am new to SQL administration. >From a list of IDs that are the primary key in one table (i.e. Customer Table), I want to make changes in tables that use those IDs as a foreign key. Basically I want to say: If fk_ID is in list then do these statements to that record
0
1195
by: lread | last post by:
This is a simplistic test table I am trying to create. The syntax is directly based up on the sample code from the BI Redbook: CREATE TABLE CUSDTA021/MQT_DB AS ( SELECT SUM(ML1OQ) AS TOTAL_SUM, M1PN FROM FRNDTA021/M1P M1P WHERE M1LOT# = '' GROUP BY M1PN
7
7765
by: Zri Man | last post by:
I have searched far and wide (not wide enough some might chip in) but cannot find the syntax for creating a staging table for an MQT. IBM manuals talk long and longer in serveral sections of this "marvel" but there is no indication of what it takes to create one. I have seen indications that appear to suggest that the CREATE table statement is all I need. They also seem to suggest that the Staging table and MQT are created in
1
11248
by: Sandesh | last post by:
Hello All, Me saying " has any body come across such error would be underestimating". Well I am getting a very peculiar and unique error "Line 1: Incorrect syntax near 'Actions'." Explaining you the scene is the following Stored Proc.
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9325
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.