By using query, how do I create a table in a database instead of a schema in SSMS - mysql

I know using the CREATE TABLE [example_schema].[example table] creates the table in the schema but I want to create the table in a database instead, but I don't know the syntax
CREATE TABLE Royal_Poly_DB.staff_relation (
"staff_no" CHAR(4) NOT NULL,
"staff_name" VARCHAR(100) NOT NULL,
"supervisor" CHAR(4) NULL,
"dob" DATE NOT NULL,
"grade" CHAR(5) NOT NULL,
"marital_status" CHAR(1) NOT NULL,
"pay" DECIMAL(7,2) NULL,
"allowance" DECIMAL(7,2) NULL,
"hourly_rate" DECIMAL(7,2) NULL,
"gender" CHAR(1) NOT NULL,
"citizenship" VARCHAR(10) NOT NULL,
"join_yr" INT NOT NULL,
"dept_cd" VARCHAR(5) NOT NULL,
"type_of_employment" CHAR(2) NOT NULL,
"highest_qln" VARCHAR(10) NOT NULL,
"designation" VARCHAR(20) NOT NULL,
PRIMARY KEY (staff_no))

Right click the database in the object explorer and select
"New Query" then add in you code there

Related

Mysql Trigger Insert row Another Table using matching data

I have 3 tables:
CREATE TABLE `UrunPaketDetay`(
`UrunPaketDetay` int NOT NULL AUTO_INCREMENT,
`UrunPaketNo` int NULL,
`Tarih` date NULL,
`Barkod` varchar(14) NOT NULL,
`Urun` varchar(50) NULL,
`SunumSekli` varchar(50) NULL,
`IslemeSekli` varchar(50) NULL,
`PaketlemeSekli` varchar(50) NULL,
`Kalibre` varchar(50) NULL,
`Kilo` double NULL,
`GlazeOran` varchar(50) NULL,
`Uretici` varchar(190) NULL,
`PaletKod` varchar(50) NULL,
PRIMARY KEY (`UrunPaketDetay`)
)CHARACTER SET utf8;
CREATE TABLE `CkisEks`(
`CikId` int NOT NULL AUTO_INCREMENT,
`Tarih` date NULL,
`Musteri` varchar(190) NULL,
`TeslimatYer` varchar(50) NULL,
`CikisSaati` time NULL,
`AracPlakasi` varchar(18) NULL,
`AracTel` varchar(16) NULL,
`KonteynirNo` varchar(50) NULL,
`PaletKod` varchar(12) NULL,
`Kilo` double NULL,
PRIMARY KEY (`CikId`)
)CHARACTER SET utf8;
CREATE TABLE `Ckis_Detay`(
`CD_Id` int NOT NULL AUTO_INCREMENT,
`CikId` int NULL,
`Barkod` varchar(50) NULL,
`Urun` varchar(50) NULL,
`Kalibre` varchar(50) NULL,
`Kilo` double NULL,
`Uretici` varchar(50) NULL,
`Musteri` varchar(190) NULL,
`PaletKod` varchar(50) NULL,
`Tarih` date NULL,
PRIMARY KEY (`CD_Id`)
)CHARACTER SET utf8;
I fill up my first table. After on 2nd table I call PaletKod row. PaletKod row autofill Kilo Row on 2nd table from 1st table.
But I need when I fill PaletKod to my 2nd table how can I select Paletkod from first table and fill my 3rd table values (Uretici, Urun, Kilo, Kalibre )?
I need trigger code. Can you help?
From My Understanding to do this,
DELIMITER $$
CREATE TRIGGER Insert_UrunPaketDetay
AFTER INSERT ON UrunPaketDetay
FOR EACH ROW
INSERT INTO Ckis_Detay (Uretici,Urun,Kilo,Kalibre)
VALUES
(UrunPaketDetay.Uretici,UrunPaketDetay.Urun
,UrunPaketDetay.Kilo,UrunPaketDetay.Kalibre);
END$$
DELIMITER ;
Try this code

Database is not importing giving following error

I am trying to import a database file on local server using wamp . I am getting following error. How this can be resolved, Thank you for all your help
SQL query:
CREATE TABLE IF NOT EXISTS `wp_bwg_theme` (
`id` bigint(20) NOT NULL,
`name` varchar(255) NOT NULL,
`thumb_margin` int(4) NOT NULL,
`thumb_padding` int(4) NOT NULL,
`thumb_border_radius` varchar(32) NOT NULL,
`thumb_border_width` int(4) NOT NULL,
`thumb_border_style` varchar(16) NOT NULL,
`thumb_border_color` varchar(8) NOT NULL,
`thumb_bg_color` varchar(8) NOT NULL,
`thumbs_bg_color` varchar(8) NOT NULL,
`thumb_bg_transparent` int(4) NOT NULL,
`thumb_box_shadow` varchar(32) NOT NULL,
`thumb_transparent` int(4) NOT NULL,
`thumb_align` varchar(8) NOT NULL,
`thumb_hover_effect` varchar(128) NOT NULL,
`thumb_hover_effect_value` varchar(128) NOT NULL,
`thumb_transition` tinyint(1) NOT NULL,
`thumb_title_font_color` varchar(8) NOT NULL,
`thumb_title_font_style` varchar(16) NOT NULL,
`thumb_title_pos` varchar(8) NOT NULL,
`thumb_title_font_size` int(4) NOT NULL,
`thumb_title_font_weight` varchar(8) NOT NULL,
`thumb_title_margin` varchar(32) NOT N[...]
MySQL said: Documentation
1118 - Row size too large (> 8126). Changing some columns to TEXT or BLOB may help. In current row format, BLOB prefix of 0 bytes is stored inline.

how to calculate the number of a table's rows changed(update or insert) in a day on mysql

I have a trade records table and i want to calculate the rows of this table changed including update or insert.
I have check the information_schema in mysql.There is a table called TABLE and it has a column TABLE_ROWS.But i didn't find anything helpful.
well,this table like this
CREATE TABLE pre_actived_apk_record
(
id INT(11) PRIMARY KEY NOT NULL AUTO_INCREMENT,
appid VARCHAR(255) NOT NULL,
channelid VARCHAR(255) NOT NULL,
uid INT(11) NOT NULL,
appname VARCHAR(255) NOT NULL,
packagename VARCHAR(255) NOT NULL,
versioncode VARCHAR(255) NOT NULL,
versionname VARCHAR(255) NOT NULL,
brand VARCHAR(255) NOT NULL,
model VARCHAR(255) NOT NULL,
imei VARCHAR(255) NOT NULL,
sys_version VARCHAR(255) NOT NULL,
mac_address VARCHAR(255) NOT NULL,
imsi VARCHAR(255) NOT NULL,
iccid VARCHAR(255) NOT NULL,
uploadtime INT(11) NOT NULL,
dateline INT(11) NOT NULL,
rule INT(11) NOT NULL,
price INT(11) NOT NULL
);
And i wonder i could use some built-in method to show the result of this table chanaged.

How can I declare a table without primary key?

I am using MySQL Query Browser.
I have tried this code:
CREATE TABLE `something`.`payment_something` (
`firstName` varchar(15) NOT NULL,
`lastName` varchar(15) NOT NULL,
`inputEmail` varchar(55) NOT NULL,
`genderRadios` varchar(15) NOT NULL,
`monthh` varchar(10) NOT NULL,
`dayy` varchar(10) NOT NULL,
`yearr` varchar(10) NOT NULL,
`postalAddress` varchar(15) NOT NULL,
`phoneNumber` varchar(15) NOT NULL,
`ZipCode` varchar(15) NOT NULL,
`CreditCard` varchar(15) NOT NULL,
`expireMonth` varchar(10) NOT NULL,
`expireYear` varchar(10) NOT NULL,
`Institution` varchar(25) NOT NULL,
`textinput` varchar(15) NOT NULL,
`radios` varchar(10) NOT NULL,
PRIMARY KEY ()
) ENGINE=InnoDB DEFAULT CHARSET=greek;
of course it shows error in the PRIMARY KEY line. Any idea?
EDIT Better solution
CREATE TABLE `something`.`payment_something` (
`id` int(15) NOT NULL AUTO_INCREMENT,
`firstName` varchar(15) NOT NULL,
`lastName` varchar(15) NOT NULL,
`inputEmail` varchar(55) NOT NULL,
`genderRadios` varchar(15) NOT NULL,
`monthh` varchar(10) NOT NULL,
`dayy` varchar(10) NOT NULL,
`yearr` varchar(10) NOT NULL,
`postalAddress` varchar(15) NOT NULL,
`phoneNumber` varchar(15) NOT NULL,
`ZipCode` varchar(15) NOT NULL,
`CreditCard` varchar(15) NOT NULL,
`expireMonth` varchar(10) NOT NULL,
`expireYear` varchar(10) NOT NULL,
`Institution` varchar(25) NOT NULL,
`textinput` varchar(15) NOT NULL,
`radios` varchar(10) NOT NULL,
PRIMARY KEY ('id')
) ENGINE=InnoDB DEFAULT CHARSET=greek;
It shows wrong in the PRIMARY KEY line why?
Simply exclude the problematic line:
PRIMARY KEY ()
You don't need to have that line, if you are not actually defining a key. In your example, you will also have to remove the comma directly preceding this line, of course.
UPDATE:
In your updated example, just take the '' off of 'id' when you declare it. Use the backtick (`), instead of the apostrophe:
PRIMARY KEY (`id`)

MySQL Create Table Error 1064

I am trying to create a table in MySQL but it doesn't want to play:
create table traders(
traderID INT(9) ZEROFILL NOT NULL AUTO_INCREMENT UNSIGNED,
traderProfileName VARCHAR(64) NOT NULL,
traderPassword CHAR(128) NOT NULL,
traderFirstName VARCHAR(40) NOT NULL,
traderSurname VARCHAR(40) NOT NULL,
traderContactPhone VARCHAR(14) NOT NULL,
locationPostCode CHAR(4) NOT NULL,
traderEmail VARCHAR(120) NOT NULL,
traderBio VARCHAR(255) DEFAULT NULL,
traderReviewRating DECIMAL(5,2) DEFAULT NULL,
traderLastLogin DATETIME DEFAULT NULL,
PRIMARY_KEY(traderID)
);
And I am getting error:
"ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNSIGNED,
traderProfileName VARCHAR(64) NOT NULL,
traderPassword CHAR(128) NOT ' at line 2"
Is this something simple as I am using incorrect parameters for the table settings?
When you use UNSIGNED you must put it right beside the data type, that is: INT UNSIGNED.
Your corrected CREATE statement should look like this:
create table traders(
traderID INT(9) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY,
-- ^^^^^^^^^^^^^^^ Here is the problem.
-- Also, you can define this column as a primary key +---^^^^^^^^^^^
-- directly in the column definition |
traderProfileName VARCHAR(64) NOT NULL,
traderPassword CHAR(128) NOT NULL,
traderFirstName VARCHAR(40) NOT NULL,
traderSurname VARCHAR(40) NOT NULL,
traderContactPhone VARCHAR(14) NOT NULL,
locationPostCode CHAR(4) NOT NULL,
traderEmail VARCHAR(120) NOT NULL,
traderBio VARCHAR(255) DEFAULT NULL,
traderReviewRating DECIMAL(5,2) DEFAULT NULL,
traderLastLogin DATETIME DEFAULT NULL,
);
You may ask, "Why?" that's because there are two "types" of integer:
INT signed (which can store values from -2147483648 to 2147483647)
INT UNSIGNED (which can store values from 0 to 4294967295)
Reference:
MySQL reference: Data types > Numeric types > Integer types
Auto increment is an integer by default, no need to define unsigned.
http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html
try this
create table traders
(
traderID INT(9) ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY,
traderProfileName VARCHAR(64) NOT NULL,
traderPassword CHAR(128) NOT NULL,
traderFirstName VARCHAR(40) NOT NULL,
traderSurname VARCHAR(40) NOT NULL,
traderContactPhone VARCHAR(14) NOT NULL,
locationPostCode CHAR(4) NOT NULL,
traderEmail VARCHAR(120) NOT NULL,
traderBio VARCHAR(255) DEFAULT NULL,
traderReviewRating DECIMAL(5,2) DEFAULT NULL,
traderLastLogin DATETIME DEFAULT NULL
);
no need for unsigned
use primary key in same line as trader(id)
here working demo
You have some MySQL syntax errors. Here's the fix:
CREATE TABLE IF NOT EXISTS `traders` (
`traderID` INT(9) NOT NULL AUTO_INCREMENT,
`traderProfileName` VARCHAR(64) NOT NULL,
`traderPassword` CHAR(128) NOT NULL,
`traderFirstName` VARCHAR(40) NOT NULL,
`traderSurname` VARCHAR(40) NOT NULL,
`traderContactPhone` VARCHAR(14) NOT NULL,
`locationPostCode` CHAR(4) NOT NULL,
`traderEmail` VARCHAR(120) NOT NULL,
`traderBio` VARCHAR(255) DEFAULT NULL,
`traderReviewRating` DECIMAL(5,2) DEFAULT NULL,
`traderLastLogin` DATETIME DEFAULT NULL,
PRIMARY KEY (`traderID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1;
I would add the preferred engine, charset, collation and auto increment start number.
If you'd like to do so just substitute the last line with:
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1;
And modify as desired.
Otherwise leave the closing parenthesis.
);