-
Notifications
You must be signed in to change notification settings - Fork 0
/
SQL
56 lines (53 loc) · 1.78 KB
/
SQL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Create Database BigDataBootCamp;
#go inside the database
use BigDataBootCamp;
#command to create a table
create table if not exists
--Command to drop the database
drop database BigDataBootCamp;
--Command to Create table in a database
--Go inside the particular database
use BigDataBootCamp;
-- Command to create a table
create table if not exists employee(
id int,
name varchar(50)
);
show create table employee;
-- Drop the table---
drop table employee;
insert into employee values(1, "kul",10000,'2021-09-15');
insert into employee(salary, name, id) values(20000,'Shahin',3);
insert into employee values(1, "kul",10000,'2021-09-15'),(1, "kul",10000,'2021-09-15'),(1, "kul",10000,'2021-09-15');
-----Create table with constraints---------------
create table if not exists emplyoee_with_constraints(
id int not null,
name varchar(50) not null,
salary double,
hiring_date date default '2021-01-01',
constraint unique_id unique(id),
constraint salary_check check(salary>1000)
);
-----Class2---------------
create database class2_DB;
use class2_DB;
create table if not exists employee(
id int,
name varchar(50),
address varchar(50),
city varchar(50)
);
insert into employee values(1, "shashank", 'RJPM', 'Lucknow');
select * from employee;
####### add new column in the table##################
alter table employee DOB date;
###Modify existing column in a table##########
alter table employee modify name varchar(50);
###Drop specific column from a table####
alter table employee drop column city;
####Change or rename the particular column name to full_name####
alter table employee rename column name to full_name;
### add unique intigrity constraint on id column###
alter table employee add constraint id_unique unique(id);
## drop the constraint from an existing table###
alter table employee drop constraint id_unique;