-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdatabases.commands.txt
281 lines (165 loc) · 5.91 KB
/
databases.commands.txt
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
>>>>>>> Databases <<<<<<<<<<<<
-----------------------------------------------------------------------
Kerys:
mysql, sqlite3
mysqld, mysql-nt, mysqladmin, start server
-----------------------------------------------------------------------
-----------------------------------------------------------------------
-----------------------------------------------------------------------
-----------------------------------------------------------------------
>>>>>> Sqlite3: <<<<<<<<
c:/sqlite> type sqlite command here
.help //Displaying all commands
sqlite3 database.laravel08.db // Creating database
.databases //List names and files of attached databases
.open db_name //To open database
.tables //List tables
.schema tableName //Showing table's structure
.dump ?OBJECTS? //Render database content as SQL
.show //Show the current values for various settings
.recover //Recover as much data as possible from corrupt db.
.restore ?DB? FILE //Restore content of DB (default "main") from FILE
.load FILE ?ENTRY? //Load an extension library
.log FILE|off //Turn logging on or off. FILE can be stderr/stdout
.mode MODE ?TABLE? //Set output mode
.separator COL ?ROW? //Change the column and row separators
.excel //Display the output of next command in spreadsheet
SELECT column_list FROM table;
SELECT * FROM tracks;
SELECT DISTINCT column_list
FROM table_list
CREATE TABLE [IF NOT EXISTS] [schema_name].table_name (
column_1 data_type PRIMARY KEY,
column_2 data_type NOT NULL,
column_3 data_type DEFAULT 0,
table_constraints
) [WITHOUT ROWID];
//Example:
create table users(id int(10) primary key, name varchar(100));
SELECT trackid, name, composer, unitprice FROM tracks;
.backup ?DB? FILE //Backup DB (default "main") to FILE
/* Export all table's records to msword
sqlite> .headers on
sqlite> .mode csv
sqlite> .once d:/dataout.csv
sqlite> SELECT * FROM users;
sqlite> .system d:/dataout.csv
*/
//Export to Excel
sqlite> .excel
sqlite> SELECT * FROM users;
//In column mode, each record is shown on a separate line with the data aligned in columns.
sqlite> .mode column
sqlite> select * from users;
//
sqlite>.width
sqlite> .mode markdown
sqlite> select * from users;
Or
sqlite> .mode table
sqlite> select * from tbl1;
Or
sqlite> .mode box
sqlite> select * from tbl1;
-----------------------------------------------------------------------
>>>>> mysql MySql MYSQL <<<<<<<
Mysql on windows:
Windows cmd:
CREATE TABLE table_name (
column_1 datatype,
column_2 datatype,
column_3 datatype
);
SELECT studentID, FullName, sat_score, rcd_updated FROM student;
I:\mysql\bin> mysql -u root -p //To start server
I:\mysql\bin> mysqladmin -u root -p shutdown //To stop server
I:\mysql\bin> describe tableName
ALTER TABLE table_name
ADD column_name datatype;
And then to invoke the MySQL client:
mysql -h localhost -u root -p
ALTER TABLE customers
DROP COLUMN surname;
UPDATE table_name
SET column1 = value1,
column2 = value2, ...
WHERE condition;
UPDATE table_name1
SET table_name1.column1 = table_name2.columnA
table_name1.column2 = table_name2.columnB
FROM table_name1
JOIN table_name2 ON table_name1.ForeignKey = table_name2.Key
SELECT column_name, COUNT(*)
FROM table_name
GROUP BY column_name;
SELECT column_name, COUNT(*)
FROM table_name
GROUP BY column_name
HAVING COUNT(*) > value;
SELECT groupingField, AVG(num_field)
FROM table1
GROUP BY groupingField
SELECT studentID, FullName, AVG(sat_score)
FROM student
GROUP BY studentID, FullName;
SELECT user_only_num1 AS AgeOfServer, (user_only_num1 - warranty_period) AS NonWarrantyPeriod FROM server_table
SELECT studentID, FullName, sat_score
FROM student
ORDER BY FullName DESC;
SELECT count(*) AS studentCount FROM student;
DELETE FROM table_name
WHERE condition;
SELECT * FROM A x JOIN B y ON y.aId = x.Id
SELECT studentID, FullName, sat_score, rcd_updated
FROM student
WHERE
FullName LIKE 'Monique%' OR
FullName LIKE '%Greene';
SELECT COUNT(customer_id), name
FROM customers
GROUP BY name
HAVING COUNT(customer_id) > 2;
SELECT name
FROM customers
ORDER BY age;
SELECT name
FROM customers
ORDER BY age DESC;
SELECT name
FROM customers
ORDER BY age
OFFSET 10 ROWS;
SELECT name
FROM customers
INNER JOIN orders
ON customers.customer_id = orders.customer_id;
GRANT SELECT, UPDATE ON customers TO usr_bob;
REVOKE SELECT, UPDATE ON customers FROM usr_bob;
SAVEPOINT SAVEPOINT_NAME;
DELETE FROM customers
WHERE name = ‘Bob’;
COMMIT
ROLLBACK TO SAVEPOINT_NAME;
TRUNCATE TABLE customers;
SELECT name FROM customers
UNION
SELECT name FROM orders;
//Copy data to another table
SELECT * INTO customers
FROM customers_backup;
//Rename table's name
rename table users to user
-----------------------------------------------------------------------
MongoDB:
------------------------------------------------------------------------
>>>>>> Start & Stop Server <<<<<<<<
//Mysql server start in cmd
C:\> "C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld" OR c:/>mysqld
//Mysql server stop in cmd
C:\> "C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqladmin" -u root shutdown
OR C:\>mysqladmin -u root shutdown
OR
C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld
C:\>mysqld-nt //Start MySql Server
C:\>mysqladmin -uroot shutdown //Stop MySql Server
-----------------------------------------------------------------------------