USE myemployees;
CREATE TABLE my_employees (
id INT ( 10 ),
first_name VARCHAR ( 10 ),
last_name VARCHAR ( 10 ),
userid VARCHAR ( 10 ),
salary DOUBLE ( 10, 2 ));
CREATE TABLE users ( id INT, userid VARCHAR ( 10 ), department_id INT );
DESC my_employees;
#方式一:
INSERT INTO my_employees
VALUES
( 1, 'patel', 'ralph', 'rpatel', 895 ),
( 2, 'dancs', 'betty', 'bdancs', 860 ),
( 3, 'biri', 'ben', 'bbiri', 1100 ),
( 4, 'newman', 'chad', 'cnewman', 750 ),
( 5, 'ropeburn', 'audrey', 'aropebur', 1550 );
#方式二:
INSERT INTO my_employees SELECT
1,
'patel',
'ralph',
'rpatel',
895 UNION
SELECT
2,
'dancs',
'betty',
'bdancs',
860 UNION
SELECT
3,
'biri',
'ben',
'bbiri',
1100 UNION
SELECT
4,
'newman',
'chad',
'cnewman',
750 UNION
SELECT
5,
'ropeburn',
'audrey',
'aropebur',
1550;
INSERT INTO users
VALUES
( 1, 'rpatel', 10 ),
( 2, 'bdancs', 10 ),
( 3, 'bbiri', 20 ),
( 4, 'cnewman', 30 ),
( 5, 'aropebur', 40 );
UPDATE my_employees
SET last_name = "drelxer"
WHERE
id = 3;
UPDATE my_employees
SET salary = 1000
WHERE
salary < 900;
DELETE u,
e
FROM
users u
JOIN my_employees e ON u.userid = e.userid
WHERE
u.userid = "bbiri";
DELETE
FROM
my_employees;
DELETE
FROM
users;
SELECT
*
FROM
my_employees;
SELECT
*
FROM
users;
TRUNCATE TABLE my_employees;
name null type
id int(7)
name varchar(25)
#代码:
CREATE TABLE dept1 (
id INT ( 7 ),
NAME VARCHAR ( 25 ));
CREATE TABLE dept2 SELECT
department_id,
department_name
FROM
myemployees.departments;
CREATE TABLE emp5 (
id INT ( 7 ),
first_name VARCHAR ( 25 ),
last_name VARCHAR ( 25 ),
dept_id INT ( 7 ));
ALTER TABLE emp5 MODIFY COLUMN last_name VARCHAR ( 50 );
CREATE TABLE employees2 LIKE myemployees.employees;
DROP TABLE
IF
EXISTS emp5;
ALTER TABLE employees RENAME TO emp5;
ALTER TABLE emp5 ADD COLUMN test_column INT;
ALTER TABLE emp5 DROP COLUMN dept_id;
有问题的评论交流,及时更正,谢谢关注