I am trying to standardize our mysql table creation script, we have several similar names that perform similar function in several tables.
Think the column name is owner, creator, updater and it appears in multiple tables. But some tables are using the datatype as varchar(20), some are using varchar(50) and some varchar(100).
Is there a way to standardize these datatypes by using an alias or typedef of some kind ?
Example, instead of creating tables in my sql script create-tables.sql like :
create table A ( owner varchar(20) );
create table B ( creator varchar(50) );
create table C ( updater varchar(100) );
I do something like :
alias datatype_name is varchar(20)
create table A ( owner datatype_name );
create table B ( creator datatype_name );
create table C ( updater datatype_name );
Of course in MySQL these tables can use the data type varchar(20) , I am certainly not expecting the alias to carry forward from the creation sql script to mysql.
I am a beginner in SQL, I created a table called Product and in one of the columns I placed SURNAME instead of DESCRIPTION, I am trying to follow the code below but this syntax error is appearing:
alter table palmsdatabase.product
CHANGE COLUMN SURNAME DESCRIPTION NVARCHAR(500) NULL
Just try this:
ALTER TABLE Product CHANGE `DESCRIPTION` `SURNAME` NVARCHAR(500) NULL;
and check for more information: Alter Table
I dont know what mistake i made in creating the following table?
create table users(Time int(11) not NULL,
userid text,group text,
jobs_running int(11),
jobs_pending int(11),
job_limit int(11),
run_failures int(11),
queues text,
ATP int(11),
pend_reasons int(11));
Just do a simple quotes and this will make your query run , no need to change your column name
Below is running query
Note
create table users(Time int(11) not NULL,userid text,`group` text,jobs_running int(11),jobs_pending int(11),job_limit int(11),run_failures int(11),queues text,ATP int(11),pend_reasons int(11));
This is general problem and many time generate when we use some mysql or any database management system related word like e.g. group, by, date etc for table field.
Here problem is you use "group" word for table field. You just need to backtick(`). please note below query:
create table users(Time int(11) not NULL,userid text,`group` text,jobs_running int(11),jobs_pending int(11),job_limit int(11),run_failures int(11),queues text,ATP int(11),pend_reasons int(11))
Rename the column name group to any other name. It's a keyword hence giving error.
Try this.
create table users(Time int(11) not NULL,
userid text,
groups text,
jobs_running int(11),
jobs_pending int(11),
job_limit int(11),
run_failures int(11),
queues text,
ATP int(11),
pend_reasons int(11));
Here is what Mimer SQL-2003 Validator said:
create table users(Time int(11) not NULL,userid text,group text,jobs_running
^---- ^---
int(11),jobs_pending int(11),job_limit int(11),run_failures int(11),queues
text,ATP int(11),pend_reasons int(11));
syntax error: Time
correction: <identifier>
syntax error: group
correction: <identifier>
I'm making a C# application and i want to encrypt table name and column name
Now my query looks like this:
CREATE TABLE 'fmx8ttwCrwiloPwF0cJzRA==' ('0W7pGx8jrh2+NiWh57iUhA==' INT auto_increment, 'nAra1k/bvX0hVmIgB6cVdw==' INT, 'ypDGo22BnDzv6lkYrRVOvg==' LONGTEXT) DEFAULT CHARSET=utf8
What is wrong with it?
How can I fix it?
I need to use special charset...
I have SQL CREATE statements for MySQL. They have KEY.
Example :
CREATE TABLE a (
a varchar(25) NOT NULL DEFAULT '',
b varchar(20) NOT NULL DEFAULT '',
KEY location (a)
);
What is the CREATE statement for this table in MSSQL ? The KEY keyword does cause problem.
CREATE TABLE database1.dbo.a (
a nvarchar(25),
b nvarchar(25),
)
GO
CREATE INDEX a_index
ON database1.dbo.a(a)
GO
...change db and schema names
if key is the column name, you could use square brackets to surround it..and then run the sql statement, like this:
[KEY]