Skip to content

Commit b91ba5e

Browse files
codes added
codes added
1 parent 73dd3a0 commit b91ba5e

File tree

144 files changed

+1693
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+1693
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CREATE TABLE tasks (
2+
task_name VARCHAR(255),
3+
complete BOOLEAN );
4+
5+
INSERT INTO tasks VALUES ('Study SQL', false);
6+
7+
SELECT * FROM tasks;
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CREATE TABLE persons (
2+
first_name VARCHAR(255),
3+
last_name VARCHAR(255)
4+
);
5+
6+
INSERT INTO persons VALUES ('John', 'Thompson');
7+
8+
SELECT concat(first_name, ' ', last_name) as full_name from persons;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use employees;
2+
3+
select * from departments;
4+
5+
insert into departments values ('d999', 'foo');
6+
7+
delete from departments where dept_no = 'd999';
8+
9+
10+
-- Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Editor and reconnect.
11+
delete from departments;
12+
13+
-- wont work
14+
delete from departments where dept_no like '%';
15+
16+
delete from departments where dept_no like 'd%';
17+
18+
19+
-- view table information
20+
SELECT cols.TABLE_NAME, cols.COLUMN_NAME, cols.ORDINAL_POSITION,
21+
cols.COLUMN_DEFAULT, cols.IS_NULLABLE, cols.DATA_TYPE,
22+
cols.CHARACTER_MAXIMUM_LENGTH, cols.CHARACTER_OCTET_LENGTH,
23+
cols.NUMERIC_PRECISION, cols.NUMERIC_SCALE,
24+
cols.COLUMN_TYPE, cols.COLUMN_KEY, cols.EXTRA,
25+
cols.COLUMN_COMMENT, refs.REFERENCED_TABLE_NAME, refs.REFERENCED_COLUMN_NAME,
26+
cRefs.UPDATE_RULE, cRefs.DELETE_RULE,
27+
links.TABLE_NAME, links.COLUMN_NAME,
28+
cLinks.UPDATE_RULE, cLinks.DELETE_RULE
29+
FROM INFORMATION_SCHEMA.`COLUMNS` as cols
30+
LEFT JOIN INFORMATION_SCHEMA.`KEY_COLUMN_USAGE` AS refs
31+
ON refs.TABLE_SCHEMA=cols.TABLE_SCHEMA
32+
AND refs.REFERENCED_TABLE_SCHEMA=cols.TABLE_SCHEMA
33+
AND refs.TABLE_NAME=cols.TABLE_NAME
34+
AND refs.COLUMN_NAME=cols.COLUMN_NAME
35+
LEFT JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS cRefs
36+
ON cRefs.CONSTRAINT_SCHEMA=cols.TABLE_SCHEMA
37+
AND cRefs.CONSTRAINT_NAME=refs.CONSTRAINT_NAME
38+
LEFT JOIN INFORMATION_SCHEMA.`KEY_COLUMN_USAGE` AS links
39+
ON links.TABLE_SCHEMA=cols.TABLE_SCHEMA
40+
AND links.REFERENCED_TABLE_SCHEMA=cols.TABLE_SCHEMA
41+
AND links.REFERENCED_TABLE_NAME=cols.TABLE_NAME
42+
AND links.REFERENCED_COLUMN_NAME=cols.COLUMN_NAME
43+
LEFT JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS cLinks
44+
ON cLinks.CONSTRAINT_SCHEMA=cols.TABLE_SCHEMA
45+
AND cLinks.CONSTRAINT_NAME=links.CONSTRAINT_NAME
46+
WHERE cols.TABLE_SCHEMA=DATABASE()
47+
AND cols.TABLE_NAME="employees";
48+
49+
-- use with caution, will clear whole database
50+
delete from employees where emp_no > 1;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use employees;
2+
3+
select * from employees;
4+
5+
INSERT INTO employees SELECT max(emp_no) + 1, '1976-02-02', 'Micheal', 'Weston', 'M', '2015-01-02' FROM employees;
6+
7+
SELECT * from employees where last_name = 'Weston';
8+
9+
UPDATE employees
10+
SET birth_date = '1976-03-02'
11+
WHERE emp_no = 500000;
12+
13+
DELETE FROM employees
14+
WHERE emp_no = 500000;
Binary file not shown.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use employees;
2+
3+
select * from employees;
4+
5+
begin;
6+
7+
INSERT INTO employees SELECT max(emp_no) + 1, '1976-02-02', 'Micheal', 'Weston', 'M', '2015-01-02' FROM employees;
8+
9+
commit;
10+
11+
SELECT * from employees where last_name = 'Weston';
12+
13+
commit;
14+
15+
UPDATE employees
16+
SET birth_date = '1976-03-02'
17+
WHERE emp_no = 500000;
18+
19+
DELETE FROM employees
20+
WHERE emp_no = 500000;
21+
22+
23+
rollback;
24+
25+
-- turn off
26+
set autocommit=0;
27+
28+
-- turn on
29+
set autocommit=1;

0 commit comments

Comments
 (0)