Question:
Can we create the table with more than 2 Long datatype fields in MYSQL ?
hanu@mumbai
2006-12-07 03:26:29 UTC
The above condition is the must. I want to create table with more than one LONG datatype and declare the two LONG fields as a Primary Key also. (Option is we create the table in PL/SQL or MYSQL with ORACLE10g features are also used). how can i create the table & primary key ?
Four answers:
anonymous
2006-12-07 06:47:50 UTC
MySQL doesn't have a LONG datatype. It has a LONGTEXT data type and a LONGBLOB data type, either of which would correspond to a LONG in PL/SQL.



Assuming, therefore, you want to create a table that has three columns: two LONGTEXT columns which will be combined to a single primary key, and a third INT column with a length of 11:



CREATE TABLE mytable

column1 LONGTEXT,

column2 LONGTEXT,

column3 INT(11)

PRIMARY KEY (column1, column2) ;
Jeff Alexander
2006-12-07 06:48:44 UTC
You have a very strange use case. Why would you want to use multiple LONG fields as a primary key? There are, however, a few options depending upon the nature of your data. Some examples:



create table sample1 (

col1 long not null,

col2 long not null,

primary key (col1(500), col2(500))

);

This will create a table that has two long fields and a primary key based upon the first 500 characters of each field. For primary keys MySQL has a limit of 1000 characters. Something to keep in mind with MySQL is the default text comparison is case insensitive.



create table sample2 (

col1 long not null,

col2 long not null,

fulltext (col1, col2)

);

This will create a table with no primary key but with a fulltext index that can be used for searching.
Kelley
2016-05-23 07:12:14 UTC
Nope, In SQL For EACH Table Only One Long Column is allowed. ERROR at line 1: ORA-01754: a table may contain only one column of type LONG
bow4bass
2006-12-07 06:28:10 UTC
two long fields isnt your problem, u cant have two primary keys for one table



make one primary and index the other for searching


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