Magento tax creation SQL

-- delete all tax definitions
DELETE FROM tax_calculation_rule;
DELETE FROM tax_class;
DELETE FROM tax_calculation_rate;
DELETE FROM tax_calculation;
 
-- create  tax_class
INSERT INTO tax_class(class_name, class_type) VALUES
('Umsatzsteuerpfichtige Güter 19%','PRODUCT'),
('Umsatzsteuerpfichtige Güter 7%','PRODUCT'),
('Umsatzsteuerfreie Güter','PRODUCT'),
('inkl. Mehrwertsteuer','CUSTOMER');
 
-- update ids
UPDATE tax_class SET class_id = 19 WHERE class_name = 'Umsatzsteuerpfichtige Güter 19%';
UPDATE tax_class SET class_id = 7 WHERE class_name = 'Umsatzsteuerpfichtige Güter 7%';
UPDATE tax_class SET class_id = 0 WHERE class_name = 'Umsatzsteuerfreie Güter';
UPDATE tax_class SET class_id = 1 WHERE class_name = 'inkl. Mehrwertsteuer';
 
-- create tax_calculation_rate
INSERT INTO tax_calculation_rate(tax_country_id, tax_region_id, tax_postcode, code, rate, zip_is_range, zip_from, zip_to) VALUES
('DE', 0, '*', '19% Steuer', 19.00, NULL, NULL, NULL),
('DE', 0, '*', '7% Steuer', 7.00, NULL, NULL, NULL),
('DE', 0, '*', '0% Steuer', 0.00, NULL, NULL, NULL);
 
 
INSERT INTO tax_calculation_rule(code, priority, position) VALUES
('Produkte mit 19% Mwst.', 2, 0),
('Produkte mit 7% Mwst.', 1, 0),
('Umsatzsteuerfreie Güter', 0, 0);
 
 
--  create roule for 19%
INSERT INTO tax_calculation	
SELECT (
	SELECT tax_calculation_rate_id
	FROM tax_calculation_rate
	WHERE code = '19% Steuer'
	AND tax_country_id = 'DE'
) tax_calculation_rate_id, (
	SELECT tax_calculation_rule_id
	FROM tax_calculation_rule
	WHERE code = 'Produkte mit 19% Mwst.'
) tax_calculation_rule_id, (
	SELECT class_id
	FROM tax_class
	WHERE class_name = 'inkl. Mehrwertsteuer'
	AND class_type = 'CUSTOMER'
) customer_tax_class_id, (
	SELECT class_id 	 	
	FROM tax_class
	WHERE class_name = 'Umsatzsteuerpfichtige Güter 19%'
	AND class_type = 'PRODUCT'
) product_tax_class_id;
 
 
--  create roule for 7%
INSERT INTO tax_calculation	
SELECT (
	SELECT tax_calculation_rate_id
	FROM tax_calculation_rate
	WHERE code = '7% Steuer'
	AND tax_country_id = 'DE'
) tax_calculation_rate_id, (
	SELECT tax_calculation_rule_id
	FROM tax_calculation_rule
	WHERE code = 'Produkte mit 7% Mwst.'
) tax_calculation_rule_id, (
	SELECT class_id
	FROM tax_class
	WHERE class_name = 'inkl. Mehrwertsteuer'
	AND class_type = 'CUSTOMER'
) customer_tax_class_id, (
	SELECT class_id 	 	
	FROM tax_class
	WHERE class_name = 'Umsatzsteuerpfichtige Güter 7%'
	AND class_type = 'PRODUCT'
) product_tax_class_id;
 
 
--  create roule for 0%
INSERT INTO tax_calculation	
SELECT (
	SELECT tax_calculation_rate_id
	FROM tax_calculation_rate
	WHERE code = '0% Steuer'
	AND tax_country_id = 'DE'
) tax_calculation_rate_id, (
	SELECT tax_calculation_rule_id
	FROM tax_calculation_rule
	WHERE code = 'Umsatzsteuerfreie Güter'
) tax_calculation_rule_id, (
	SELECT class_id
	FROM tax_class
	WHERE class_name = 'inkl. Mehrwertsteuer'
	AND class_type = 'CUSTOMER'
) customer_tax_class_id, (
	SELECT class_id 	 	
	FROM tax_class
	WHERE class_name = 'Umsatzsteuerfreie Güter'
	AND class_type = 'PRODUCT'
) product_tax_class_id;
 
-- update ids (old)
--UPDATE tax_calculation_rule SET tax_calculation_rule_id = 19 where code = 'Produkte mit 19% Mwst.';
--UPDATE tax_calculation_rule SET tax_calculation_rule_id = 7 where code = 'Produkte mit 7% Mwst.';
--UPDATE tax_calculation_rule SET tax_calculation_rule_id = 0 where code = 'Umsatzsteuerfreie Güter';
 
-- view all tax roules
SELECT * FROM tax_class;
 
--SELECT tax_calculation_rule_id, code
--FROM tax_calculation_rule