0% found this document useful (0 votes)
3 views2 pages

SQL Table Creation and Insertion Guide

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

SQL Table Creation and Insertion Guide

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Input:-

CREATE TABLE department (

dept_id SERIAL PRIMARY KEY,

dept_name VARCHAR(100) NOT NULL,

location VARCHAR(100) DEFAULT 'Main Campus'

);

CREATE TABLE student (

student_id SERIAL PRIMARY KEY,

name VARCHAR(50) NOT NULL,

age INT CHECK (age >= 18),

email VARCHAR(100) UNIQUE,

dept_id INT NOT NULL,

CONSTRAINT fk_dept FOREIGN KEY (dept_id) REFERENCES department(dept_id)

);

INSERT INTO department (dept_name, location) VALUES

('Coms', 'GOA'),

('I.T', ' Maharastra'),

('Mechanical', DEFAULT);

INSERT INTO student (name, age, email, dept_id) VALUES

('Vedant', 20, 'Vedant@[Link]', 1),

('Prajwal', 22, 'Prajwal@[Link]', 2),

('Harsh', 19, 'Harsh@[Link]', 3);

SELECT * FROM department;

SELECT * FROM student;


Output:-

You might also like