Mysql Part1

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

CREATE TABLE SCHOOL

(ROLL_NO INT,
STUD_NAME VARCHAR(10),
MARKS INT);

INSERT INTO SCHOOL VALUES (1,'KABIR',78);


INSERT INTO SCHOOL VALUES (2,'SHRI',80);
INSERT INTO SCHOOL VALUES (3,'KHUSHI',90);

(1,'KABIR',78)
(2,'SHRI',89)
(3,'KHUSHI',99)
(4,'MOHIT',85)

CREATE TABLE PRODUCT5


(PCODE INT PRIMARY KEY,
PNAME VARCHAR(20) NOT NULL,
PPRICE INT NULL CHECK(PPRICE>=100 AND PPRICE<=200) );

INSERT INTO PRODUCT4 VALUES(2,'GOOD')

INSERT INTO PRODUCT1 VALUES(2,'SUGAR',900)

INSERT INTO PRODUCT1 VALUES(2,NULL,900)

INSERT INTO PRODUCT1(PCODE,PNAME) VALUES(2,'FG')

CREATE TABLE PRODUCT6


(
PCODE INT REFERENCES PRODUCT5(PCODE),
PQUA CHAR(10)
)

CREATE TABLE PRODUCT7


(
PCODE INT,
PQUA CHAR(10) DEFAULT 'GOOD'
)

create database prouct;


use product

CREATE TABLE product7


(pcode int NOT NULL,
pname varchar(20));

alter table product7


add primary key(pcode);

#NEW QUERY

CREATE TABLE STUDREC1


(ROLL_NO INT NOT NULL,
STUD_NAME VARCHAR(50));
CREATE TABLE STUDREC2
(ROLL_NO INT NOT NULL,
STUD_NAME VARCHAR(50));
ALTER TABLE STUDREC1
ADD PRIMARY KEY(ROLL_NO);

ALTER TABLE STUDREC2


ADD FOREIGN KEY (ROLL_NO)
REFERENCES STUDREC1 (ROLL_NO);
INSERT INTO STUDEREC VALUES

ALTER TABLE STUDREC1 ADD ADDRESS VARCHAR(30);


SELECT*FROM TABLE;
UPDATE STUDREC1 SET ADDRESS='KOLKATA'
WHERE ROLL_NO =1;
UPDATE STUDREC1 SET ADDRESS='SEALDAH'
WHERE ADDRESS IS NULL;
SELECT* FROM STUDREC1;
+---------+-----------+---------+
| ROLL_NO | STUD_NAME | ADDRESS |
+---------+-----------+---------+
| 1 | KHUSHI | KOLKATA |
| 2 | PRIYA | HOWRAH |
| 3 | KABIR | SEALDAH |
+---------+-----------+---------
ALTER TABLE STUDREC1 MODIFY ADDRESS VARCHAR(5);
ERROR 1265 (01000): Data truncated for column 'ADDRESS' at row 1
ALTER TABLE STUDREC1 MODIFY ADDRESS VARCHAR(35);
ALTER TABLE STUDREC1 DROP ADDRESS;
SELECT* FROM STUDREC1;

ALTER TABLE STUDREC1 MODIFY STUD_NAME VARCHAR(50) NOT NULL;

#NEW QUERY
FOR MERGING TWO COLOUMNS
CREATE TABLE STUD_TABLE
-> (ROLL_NO INT PRIMARY KEY,
-> STUD_NAME VARCHAR(10));
CREATE TABLE STUD_TABLE2
-> (ROLL_NO INT REFERENCES STUD_TABLE(ROLL_NO),
-> STUD_MARKS INT);
INSERT VALUES

SELECT STUD_NAME,STUD_MARKS FROM STUD_TABLE,STUD_TABLE2 WHERE


STUD_TABLE.ROLL_NO=STUD_TABLE2.ROLL_NO;
SELECT STUD_NAME,STUD_MARKS FROM STUD_TABLE A, STUD_TABLE2 B WHERE
A.ROLL_NO=B.ROLL_NO;
OUTPUT:
+-----------+------------+
| STUD_NAME | STUD_MARKS |
+-----------+------------+
| PRITY | 89 |
| PRACHI | 98 |
+-----------+------------+

INSERT INTO MOVIE VALUES (1,

You might also like