-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.sql
More file actions
executable file
·120 lines (67 loc) · 1.94 KB
/
create.sql
File metadata and controls
executable file
·120 lines (67 loc) · 1.94 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
--- Print the table value
with T as (select * from (select level as c1 from dual connect by level <4) , (select level as c2 from dual connect by level<4))
select * from (select 'Co'||c1 as col1 , 'Ct'||C2 col2, rownum num from T)
COL1 COL2 NUM
Co1 Ct1 1
Co1 Ct2 2
Co1 Ct3 3
Co2 Ct1 4
Co2 Ct2 5
Co2 Ct3 6
Co3 Ct1 7
Co3 Ct2 8
Co3 Ct3 9
pivot (max(col2) for col1 in ('Co1' co1,'Co2' co2,'Co3' co3))
NUM CO1 CO2 CO3
6 - Ct3 -
1 Ct1 - -
7 - - Ct1
2 Ct2 - -
8 - - Ct2
4 - Ct1 -
5 - Ct2 -
3 Ct3 - -
9 - - Ct3
unpivot (unpivotelement for unpivotcolumn in ( co1 as 'Co1',co2 as 'Co2',co3 as 'Co3'))
NUM UNPIVOTCOLUMN UNPIVOTELEMENT
6 Co2 Ct3
1 Co1 Ct1
7 Co3 Ct1
2 Co1 Ct2
8 Co3 Ct2
4 Co2 Ct1
5 Co2 Ct2
3 Co1 Ct3
9 Co3 Ct3
//creating database
create database if not exist student ;
//creating table
create table tablename (
peronid int not_null auto_increment ,
name varchar(30),
address varchar(60),
primary_key(personid)
);
alter table tablename add columnname datatype ;
//example
alter table person add surname varchar(30);
//removing database
drop database databasename ;
drop table //it will delete table
truncate table //it will delete data
select version();
show tables;
select * from class ;
desc class;
select ifnull(class_name,"something") as id from class ;
select current_date();
show columns from tablename ;
#native command to export the table accessible
mysql -u username -xml -e 'select * from table ' > outputfile.xml
drop table tablename ; //delete schema and data
truncate table tablename ;// delete only data not schema
drop database databasename ; //delete all data with sechema
grant select ,insert ,update on dbname to brahma@localhost
// how to add foreign key
alter table tablename add colname int not_null ;
alter table tablename add contraint fkref foreign key (colname) reference grade(id);