0

I want to create a table in mysql:--

create table app_own(app_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
sp_id bigint(20),
title varchar(30),
description varchar(60),
details LONGTEXT(1000),
primary key(app_id ),
FOREIGN KEY (user_id) REFERENCES student(sp_id));

where app_id is the primary key and sp_id is the foreign key reference from student table..

but I am getting error:--

    ERROR 1064 (42000): You have an error in your SQL syntax; check the 
    manual that corresponds to your MySQL server version for the right 
    syntax to use near '(1000)0,primary key(app_id ),FOREIGN KEY (sp_id) 
REFERENCE' at line 1

why the error is occuring?

4 Answers 4

1

Try to Run This one:-

   use db;
CREATE TABLE parent (
    id INT UNSIGNED NOT NULL,
    PRIMARY KEY (id)
) ;

CREATE TABLE Persons
(
PID int UNSIGNED  NOT NULL AUTO_INCREMENT,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City longtext,
PRIMARY KEY (PID),
FOREIGN KEY (PID) 
        REFERENCES parent(id)
 ON DELETE CASCADE
);

LONGTEXT [CHARACTER SET charset_name] [COLLATE collation_name]

A TEXT column with a maximum length of 4,294,967,295 or 4GB (232 − 1) characters. The effective maximum length is less if the value contains multibyte characters. The effective maximum length of LONGTEXT columns also depends on the configured maximum packet size in the client/server protocol and available memory. Each LONGTEXT value is stored using a 4-byte length prefix that indicates the number of bytes in the value.

Sign up to request clarification or add additional context in comments.

5 Comments

I have tried your code..I got message:--ERROR 1005 (HY000): Can't create table 'mydatabase.persons' (errno: 150)
Have u used Unsigned for the primary key of parent table
Is there any table with the name Parent in the DB where u r trying to create table
Nopes..Its clean..I have copied and pasted your code
have u replaced db with ur dbname
0

You should user varchar(1000) in place of longtext(1000).

Moreover user_id column doesn't exist in you table.

Comments

0

You can´t specify the LONGTEXT in this context. Have a look in the manual.

Change your code to:

create table app_own(app_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
sp_id bigint(20),
title varchar(30),
description varchar(60),
details LONGTEXT,
primary key(app_id),
FOREIGN KEY (user_id) REFERENCES student(sp_id));

Comments

0

Also, you shouldn't be using spaces inbetween the brackets at primary key(app_id).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.