Click here to Skip to main content
15,917,795 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi all,
I'm new to mysql,Can we create user defined tables in mysql as we do in sql server.
if possible can u provide me an example.

This is my table
CREATE TABLE `mstschoolinformation` (
  `Schoolid` int(11) NOT NULL,
  `SchoolName` varchar(100) CHARACTER SET utf8 NOT NULL,
  `RegnNo` varchar(30) CHARACTER SET utf8 NOT NULL,
  `Regdby` varchar(100) CHARACTER SET utf8 NOT NULL,
  `Establishedon` datetime NOT NULL,
  `address` varchar(300) CHARACTER SET utf8 NOT NULL,
  `PrimaryorHighSchool` bit(1) DEFAULT NULL,
  PRIMARY KEY (`Schoolid`)

this is the contact table where i have multiple contact information
create table ContactDetails
(
Schoolid int,
contactno nvarchar(20))

the stored procedure to insert the inforamtion in the schoolinformation table is the following
CREATE PROCEDURE `MstSchoolInformation_Insert_Update`(
In SchoolId int,
In SchoolName nvarchar(100),
In RegnNo nvarchar(100),
In RegdBy nvarchar(100),
In EstablishedOn datetime,
In address nvarchar(300),
In PrimaryorHighSchool bit,
In typeoffunction char
)
begin	
DECLARE MAXID INT;
SELECT ifnull(max(SchoolId),"0")+1 INTO MAXID FROM MSTSCHOOLINFORMATION;
        IF typeoffunction='I' THEN
                    insert into MstSchoolInformation 
                     (SchoolId,
                        SchoolName,
                        RegnNo,
                        RegdBy,
                        EstablishedOn,
                        address,
                        PrimaryorHighSchool) values 
                        (MAXID,
                        SchoolName,
                        RegnNo,
                        RegdBy,
                        EstablishedOn,
                        address,
                        PrimaryorHighSchool);		
 
/* here i will insert the contact info if can be passed as udt like sql*/
        ELSEIF typeoffunction='U' THEN
                /*SET TRANSACTION ISOLATION LEVEL Repeatable read
                start transaction*/
                    
                        update MstSchoolInformation  set SchoolName=SchoolName,
                            RegnNo=RegnNo,
                            RegdBy=RegdBy,
                            EstablishedOn=EstablishedOn,
                            address=address,
                            PrimaryorHighSchool=PrimaryorHighSchool 
                        where SchoolId=SchoolId;
                    
                /*commit;*/
        END IF;
end


Thanks in advance
Posted
Updated 29-Nov-10 23:47pm
v3
Comments
Rod Kemp 30-Nov-10 5:49am    
Moved your table and stored procedure info from the "answer" to the question.
If you need to add information that people request add it to your original question by clicking on "Improve Question" don't add an answer.

Yes you can. Search Google and you will see a lot of examples. Good luck!
 
Share this answer
 
yes .. plzz share ur Database nd i will help u!
 
Share this answer
 
Comments
bgadarsh 30-Nov-10 5:14am    
This is my table
CREATE TABLE `mstschoolinformation` (
`Schoolid` int(11) NOT NULL,
`SchoolName` varchar(100) CHARACTER SET utf8 NOT NULL,
`RegnNo` varchar(30) CHARACTER SET utf8 NOT NULL,
`Regdby` varchar(100) CHARACTER SET utf8 NOT NULL,
`Establishedon` datetime NOT NULL,
`address` varchar(300) CHARACTER SET utf8 NOT NULL,
`PrimaryorHighSchool` bit(1) DEFAULT NULL,
PRIMARY KEY (`Schoolid`)

this is the contact table where i have multiple contact information
create table ContactDetails
(
Schoolid int,
contactno nvarchar(20))

the stored procedure to insert the inforamtion in the schoolinformation table is the following
CREATE PROCEDURE `MstSchoolInformation_Insert_Update`(
In SchoolId int,
In SchoolName nvarchar(100),
In RegnNo nvarchar(100),
In RegdBy nvarchar(100),
In EstablishedOn datetime,
In address nvarchar(300),
In PrimaryorHighSchool bit,
In typeoffunction char
)
begin
DECLARE MAXID INT;
SELECT ifnull(max(SchoolId),"0")+1 INTO MAXID FROM MSTSCHOOLINFORMATION;
IF typeoffunction='I' THEN
insert into MstSchoolInformation
(SchoolId,
SchoolName,
RegnNo,
RegdBy,
EstablishedOn,
address,
PrimaryorHighSchool) values
(MAXID,
SchoolName,
RegnNo,
RegdBy,
EstablishedOn,
address,
PrimaryorHighSchool);


/* here i will insert the contact info if can be passed as udt like sql*/
ELSEIF typeoffunction='U' THEN
/*SET TRANSACTION ISOLATION LEVEL Repeatable read
start transaction*/

update MstSchoolInformation set SchoolName=SchoolName,
RegnNo=RegnNo,
RegdBy=RegdBy,
EstablishedOn=EstablishedOn,
address=address,
PrimaryorHighSchool=PrimaryorHighSchool
where SchoolId=SchoolId;

/*commit;*/
END IF;
end

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900