Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MaxDB - Everything about MaxDB, formerly known as SAP DB
MySQL++ - Programming with the C++ API to MySQL
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
ODBC - ODBC with the MySQL Connector/ODBC driver
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
mysql openssl Question
mysql:it 's a db not a dbms how it 's possible?!
Does the binary log enabling affect the MySQL performances?
Strange behavior, Table Level Permission
FULLTEXT query format question
Preventing Duplicate Entries
Comparing and writing out BLOBS
Executing MySQL Commands From Within C Program
Can 't access mysql after kernel upgrade
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Downgrade Mysql from 4 to 3 23
MySQL Cluster Software
mysql test 4 1 fails with the gis test
ERROR 2002: Can 't connect to local MySQL server through socket
Getting Identity after INSERT
Update one field with more fields from another table
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
mysql have same function mthod as Oracle decode()
 
Help With Insert Statements

Help With Insert Statements

2006-06-02       - By Scott Purcell

 Back
Hello,



I am working through ProSpring book, in which they are using Postgres. I
need to convert the following inserts into Mysql 5. The table 'Test' ,
'Customer' work fine, but 'CustomerAddresses' blows up on the delete
cascade portion.



As I was trying to figure out the error, another question was posed. The
'Constraint'. Doesn't that just tell the column that the values within
the table must be unique? Or does it create an index? I have always been
confused on that.



Thanks,

Scott







drop table Test;

drop table CustomerPermissions;

drop table CustomerAddresses;

drop table Permissions;

drop table Customers;



create table Test (

           TestId serial not null,

           Name varchar(50) not null,

           RunDate timestamp not null,



           constraint PK_TestId primary key (TestId)

);





create table Customers (

           CustomerId serial not null,

           FirstName varchar(50) not null,

           LastName varchar(50) not null,

           

           constraint PK_CustomerId primary key (CustomerId)

);





create table CustomerAddresses (

           CustomerAddressId serial not null,

           Customer int not null,

           Line1 varchar(50) not null,

           Line2 varchar(50) not null,

           City varchar(50) not null,

           PostCode varchar(50) not null,

           

           constraint PK_CustomerAddressId primary key
(CustomerAddressId),

           constraint FK_Customer foreign key (Customer) references
Customers (CustomerId) on delete cascade on update cascade

);