Search Results

Search found 1805 results on 73 pages for 'varchar'.

Page 5/73 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Entity Framework How to specify paramter type in generated SQL (SQLServer 2005) Nvarchar vs Varchar

    - by Gratzy
    In entity framework I have an Entity 'Client' that was generated from a database. There is a property called 'Account' it is defined in the storage model as: <Property Name="Account" Type="char" Nullable="false" MaxLength="6" /> And in the Conceptual Model as: <Property Name="Account" Type="String" Nullable="false" /> When select statements are generated using a variable for Account i.e. where m.Account == myAccount... Entity Framework generates a paramaterized query with a paramater of type NVarchar(6). The problem is that the column in the table is data type of char(6). When this is executed there is a large performance hit because of the data type difference. Account is an index on the table and instead of using the index I believe an Index scan is done. Anyone know how to force EF to not use Unicode for the paramater and use Varchar(6) instead?

    Read the article

  • expand a varchar column very slowly , why?

    - by francs
    Hi We need to modify a column of a big product table , usually normall ddl statments will be excutely fast ,but the above ddl statmens takes about 10 minnutes?I wonder know the reason! I just want to expand a varchar column?The following is the detailsl --table size wapreader_log= select pg_size_pretty(pg_relation_size('log_foot_mark')); pg_size_pretty ---------------- 5441 MB (1 row) --table ddl wapreader_log= \d log_foot_mark Table "wapreader_log.log_foot_mark" Column | Type | Modifiers -------------+-----------------------------+----------- id | integer | not null create_time | timestamp without time zone | sky_id | integer | url | character varying(1000) | refer_url | character varying(1000) | source | character varying(64) | users | character varying(64) | userm | character varying(64) | usert | character varying(64) | ip | character varying(32) | module | character varying(64) | resource_id | character varying(100) | user_agent | character varying(128) | Indexes: "pk_log_footmark" PRIMARY KEY, btree (id) --alter column wapreader_log= \timing Timing is on. wapreader_log= ALTER TABLE wapreader_log.log_foot_mark ALTER column user_agent TYPE character varying(256); ALTER TABLE Time: 603504.835 ms

    Read the article

  • Error in SQL. Can not find it.

    - by kmsboy
    Error in SQL. Can not find it. DECLARE @year VARCHAR (4), @month VARCHAR (2), @day VARCHAR (2), @weekday VARCHAR (2), @hour VARCHAR (2), @archivePath VARCHAR (128), @archiveName VARCHAR (128), @archiveFullName VARCHAR (128) SET @year = CAST(DATEPART(yyyy, GETDATE()) AS VARCHAR) SET @month = CAST(DATEPART(mm, GETDATE()) AS VARCHAR) SET @day = CAST(DATEPART(dd, GETDATE()) AS VARCHAR) SET @weekday = CAST(DATEPART (dw, GETDATE()) AS VARCHAR) SET @hour = CAST(DATEPART (hh, GETDATE()) AS VARCHAR) SET @archivePath = 'd:\1c_new\backupdb\' SET @archiveName = 'TransactionLog_' + @year + '_' + @month + '_' + @day + '_' + @hour + '.bak' SET @archiveFullName = @archivePath + @archiveName BACKUP LOG [xxx] TO DISK = @archiveFullName WITH INIT , NOUNLOAD , NAME = N'?????????? ??? ??????????', SKIP , STATS = 10, DESCRIPTION = N'?????????? ??? ??????????', NOFORMAT

    Read the article

  • Conversion failed when converting the varchar value to int

    - by onedaywhen
    Microsoft SQL Server 2008 (SP1), getting an unexpected 'Conversion failed' error. Not quite sure how to describe this problem, so below is a simple example. The CTE extracts the numeric portion of certain IDs using a search condition to ensure a numeric portion actually exists. The CTE is then used to find the lowest unused sequence number (kind of): CREATE TABLE IDs (ID CHAR(3) NOT NULL UNIQUE); INSERT INTO IDs (ID) VALUES ('A01'), ('A02'), ('A04'), ('ERR'); WITH ValidIDs (ID, seq) AS ( SELECT ID, CAST(RIGHT(ID, 2) AS INTEGER) FROM IDs WHERE ID LIKE 'A[0-9][0-9]' ) SELECT MIN(V1.seq) + 1 AS next_seq FROM ValidIDs AS V1 WHERE NOT EXISTS ( SELECT * FROM ValidIDs AS V2 WHERE V2.seq = V1.seq + 1 ); The error is, 'Conversion failed when converting the varchar value 'RR' to data type int.' I can't understand why the value ID = 'ERR' should be being considered for conversion because the predicate ID LIKE 'A[0-9][0-9]' should have removed the invalid row from the resultset. When the base table is substituted with an equivalent CTE the problem goes away i.e. WITH IDs (ID) AS ( SELECT 'A01' UNION ALL SELECT 'A02' UNION ALL SELECT 'A04' UNION ALL SELECT 'ERR' ), ValidIDs (ID, seq) AS ( SELECT ID, CAST(RIGHT(ID, 2) AS INTEGER) FROM IDs WHERE ID LIKE 'A[0-9][0-9]' ) SELECT MIN(V1.seq) + 1 AS next_seq FROM ValidIDs AS V1 WHERE NOT EXISTS ( SELECT * FROM ValidIDs AS V2 WHERE V2.seq = V1.seq + 1 ); Why would a base table cause this error? Is this a known issue? UPDATE @sgmoore: no, doing the filtering in one CTE and the casting in another CTE still results in the same error e.g. WITH FilteredIDs (ID) AS ( SELECT ID FROM IDs WHERE ID LIKE 'A[0-9][0-9]' ), ValidIDs (ID, seq) AS ( SELECT ID, CAST(RIGHT(ID, 2) AS INTEGER) FROM FilteredIDs ) SELECT MIN(V1.seq) + 1 AS next_seq FROM ValidIDs AS V1 WHERE NOT EXISTS ( SELECT * FROM ValidIDs AS V2 WHERE V2.seq = V1.seq + 1 );

    Read the article

  • Problem in Saving Multi Level Models in YII

    - by Waqar
    My Table structure for user and his adress detail is as follows CREATE TABLE tbl_users ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, loginname varchar(128) NOT NULL, enabled enum("True","False"), approved enum("True","False"), password varchar(128) NOT NULL, email varchar(128) NOT NULL, role_id int(20) NOT NULL DEFAULT '2', name varchar(70) NOT NULL, co_type enum("S/O","D/O","W/O") DEFAULT "S/O", co_name varchar(70), gender enum("MALE","FEMALE","OTHER") DEFAULT "MALE", dob date DEFAULT NULL, maritalstatus enum("SINGLE","MARRIED","DIVORCED","WIDOWER") DEFAULT "MARRIED", occupation varchar(100) DEFAULT NULL, occupationtype_id int(20) DEFAULT NULL, occupationindustry_id int(20) DEFAULT NULL, contact_id bigint(20) unsigned DEFAULT NULL, signupreason varchar(500), PRIMARY KEY (id), UNIQUE KEY loginname (loginname), UNIQUE KEY email (email), FOREIGN KEY (role_id) REFERENCES tbl_roles (id), FOREIGN KEY (occupationtype_id) REFERENCES tbl_occupationtypes (id), FOREIGN KEY (occupationindustry_id) REFERENCES tbl_occupationindustries (id), FOREIGN KEY (contact_id) REFERENCES tbl_contacts (id) ) ENGINE=InnoDB; CREATE TABLE tbl_contacts ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, contact_type enum("cres","pres","coff"), address varchar(300) DEFAULT NULL, landmark varchar(100) DEFAULT NULL, district_id int(11) DEFAULT NULL, city_id int(20) DEFAULT NULL, state_id int(20) DEFAULT NULL, pin_id bigint(20) unsigned DEFAULT NULL, area_id bigint(20) unsigned DEFAULT NULL, po_id bigint(20) unsigned DEFAULT NULL, phone1 varchar(20) DEFAULT NULL, phone2 varchar(20) DEFAULT NULL, mobile1 varchar(20) DEFAULT NULL, mobile2 varchar(20) DEFAULT NULL, PRIMARY KEY (id), FOREIGN KEY (district_id) REFERENCES tbl_districts (id), FOREIGN KEY (city_id) REFERENCES tbl_cities (id), FOREIGN KEY (state_id) REFERENCES tbl_states (id) ) ENGINE=InnoDB; CREATE TABLE tbl_states ( id int(20) NOT NULL AUTO_INCREMENT, name varchar(70) DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB; CREATE TABLE tbl_districts ( id int(20) NOT NULL AUTO_INCREMENT, name varchar(70) DEFAULT NULL, state_id int(20) DEFAULT NULL, PRIMARY KEY (id), FOREIGN KEY (state_id) REFERENCES tbl_states (id) ) ENGINE=InnoDB; CREATE TABLE tbl_cities ( id int(20) NOT NULL AUTO_INCREMENT, name varchar(70) DEFAULT NULL, district_id int(20) DEFAULT NULL, state_id int(20) DEFAULT NULL, PRIMARY KEY (id), FOREIGN KEY (district_id) REFERENCES tbl_districts (id), FOREIGN KEY (state_id) REFERENCES tbl_states (id) ) ENGINE=InnoDB; The relationship is as follows User has multiple contacts i.e Permanent Address, Current Address, Office Address. Each Contact has state and City. User-Contact-state like this How to save models of this structure in one go. Please provide a reply ASAP

    Read the article

  • Oracle User definied aggregate function for varray of varchar

    - by baju
    I am trying to write some aggregate function for the varray and I get this error code when I'm trying to use it with data from the DB: ORA-00600 internal error code, arguments: [kodpunp1], [], [], [], [], [], [], [], [], [], [], [] [koxsihread1], [0], [3989], [45778], [], [], [], [], [], [], [], [] Code of the function is really simple(in fact it does nothing ): create or replace TYPE "TEST_VECTOR" as varray(10) of varchar(20) ALTER TYPE "TEST_VECTOR" MODIFY LIMIT 4000 CASCADE create or replace type Test as object( lastVector TEST_VECTOR, STATIC FUNCTION ODCIAggregateInitialize(sctx in out Test) return number, MEMBER FUNCTION ODCIAggregateIterate(self in out Test, value in TEST_VECTOR) return number, MEMBER FUNCTION ODCIAggregateMerge(self IN OUT Test, ctx2 IN Test) return number, MEMBER FUNCTION ODCIAggregateTerminate(self IN Test, returnValue OUT TEST_VECTOR, flags IN number) return number ); create or replace type body Test is STATIC FUNCTION ODCIAggregateInitialize(sctx in out Test) return number is begin sctx := Test(TEST_VECTOR()); return ODCIConst.Success; end; MEMBER FUNCTION ODCIAggregateIterate(self in out Test, value in TEST_VECTOR) return number is begin self.lastVector := value; return ODCIConst.Success; end; MEMBER FUNCTION ODCIAggregateMerge(self IN OUT Test, ctx2 IN Test) return number is begin return ODCIConst.Success; end; MEMBER FUNCTION ODCIAggregateTerminate(self IN Test, returnValue OUT TEST_VECTOR, flags IN number) return number is begin returnValue := self.lastVector; return ODCIConst.Success; end; end; create or replace FUNCTION test_fn (input TEST_VECTOR) RETURN TEST_VECTOR PARALLEL_ENABLE AGGREGATE USING Test; Next I create some test data: create table t1_test_table( t1_id number not null, t1_value TEST_VECTOR not null, Constraint PRIMARY_KEY_1 PRIMARY KEY (t1_id) ) Next step is to put some data to the table insert into t1_test_table (t1_id,t1_value) values (1,TEST_VECTOR('x','y','z')) Now everything is prepared to perform queries: Select test_fn(TEST_VECTOR('y','x')) from dual Query above work well Select test_fn(t1_value) from t1_test_table where t1_id = 1 Version of Oracle DBMS I use: 11.2.0.3.0 Does anyone tried do such a thing? What can be the reason that it does not work? How to solve it? Thanks in advance for help.

    Read the article

  • Search field based on multiple parameter

    - by Manoj Wadhwani
    Can anybody modify this , when i insert Emp. name it go to first search and it does not check other paramete could you plz modify this sp for exact search on based on parameter. --select * from Training_TRNS --USP_SearchEmployee '','2008-04-18 00:00:00.000','','','','','' alter Procedure USP_SearchEmployee @EmpName varchar(100)=null, @DateFrom varchar(100)=null, @DateTo varchar(100)=null, @CourseName varchar(100)=null, @JobFunction varchar(100)=null, @Region varchar(100)=null, @Status varchar(100)=null AS BEGIN if (@EmpName!='' and @EmpName is not null) BEGIN select EmpName,convert(varchar,DueDate,101) as DueDate,SpeCourse_ID as CourseName, EmpJobFunction as JOBFunction,EmpRegion as Region,Status from Training_TRNS where EmpName like '%'+@EmpName+'%' END ELSE IF (@CourseName!='' and @CourseName is not null) BEGIN select EmpName,convert(varchar,DueDate,101) as DueDate,SpeCourse_ID as CourseName, EmpJobFunction as JOBFunction,EmpRegion as Region,Status from Training_TRNS where SpeCourse_ID like '%'+@CourseName+'%' END ELSE IF (@JobFunction!='' and @JobFunction is not null) BEGIN select EmpName,convert(varchar,DueDate,101) as DueDate,SpeCourse_ID as CourseName, EmpJobFunction as JOBFunction,EmpRegion as Region,Status from Training_TRNS where EmpJobFunction like '%'+@JobFunction+'%' END ELSE IF (@Region!='' and @Region is not null) BEGIN select EmpName,convert(varchar,DueDate,101) as DueDate,SpeCourse_ID as CourseName, EmpJobFunction as JOBFunction,EmpRegion as Region,Status from Training_TRNS where EmpRegion like '%'+@Region+'%' END ELSE IF (@Status!='' and @Status is not null) BEGIN select EmpName,convert(varchar,DueDate,101) as DueDate,SpeCourse_ID as CourseName, EmpJobFunction as JOBFunction,EmpRegion as Region,Status from Training_TRNS where Status like '%'+@Status+'%' END ELSE IF (@DateFrom!='' and @DateFrom is not null) BEGIN select EmpName,convert(varchar,DueDate,101) as DueDate,SpeCourse_ID as CourseName, EmpJobFunction as JOBFunction,EmpRegion as Region,Status from Training_TRNS where convert(varchar,DueDate,101) like '%'+convert(varchar,@DateFrom,101)+'%' END Else BEGIN select EmpName,convert(varchar,DueDate,101) as DueDate,SpeCourse_ID as CourseName, EmpJobFunction as JOBFunction,EmpRegion as Region,Status from Training_TRNS END END

    Read the article

  • How to Implement search through Stored Procedure

    - by Manoj Wadhwani
    Can Any budy update thie sp for search , i think i have put search condition which is not rigth . If you have expertise in sql then update it , It's very urgent i have to upload it toady .. alter Procedure USP_SearchEmployee @EmpName varchar(100)=null, @DateFrom varchar(100)=null, @DateTo varchar(100)=null, @CourseName varchar(100)=null, @JobFunction varchar(100)=null, @Region varchar(100)=null, @Status varchar(100)=null AS BEGIN if (@EmpName!='' or @EmpName is not null) BEGIN select EmpName,convert(varchar,DueDate,101) as DueDate,SpeCourse_ID as CourseName, EmpJobFunction as JOBFunction,EmpRegion as Region,Status from Training_TRNS where EmpName like '%'+@EmpName+'%' END ELSE IF (@CourseName!='' or @CourseName is not null) BEGIN select EmpName,convert(varchar,DueDate,101) as DueDate,SpeCourse_ID as CourseName, EmpJobFunction as JOBFunction,EmpRegion as Region,Status from Training_TRNS where SpeCourse_ID like '%'+@CourseName+'%' END ELSE IF (@JobFunction!='' or @JobFunction is not null) BEGIN select EmpName,convert(varchar,DueDate,101) as DueDate,SpeCourse_ID as CourseName, EmpJobFunction as JOBFunction,EmpRegion as Region,Status from Training_TRNS where EmpJobFunction like '%'+@JobFunction+'%' END ELSE IF (@Region!='' or @Region is not null) BEGIN select EmpName,convert(varchar,DueDate,101) as DueDate,SpeCourse_ID as CourseName, EmpJobFunction as JOBFunction,EmpRegion as Region,Status from Training_TRNS where EmpRegion like '%'+@Region+'%' END ELSE IF (@Status!='' or @Status is not null) BEGIN select EmpName,convert(varchar,DueDate,101) as DueDate,SpeCourse_ID as CourseName, EmpJobFunction as JOBFunction,EmpRegion as Region,Status from Training_TRNS where Status like '%'+@Status+'%' END ELSE IF (@DateFrom!='' or @DateFrom is not null) BEGIN select EmpName,convert(varchar,DueDate,101) as DueDate,SpeCourse_ID as CourseName, EmpJobFunction as JOBFunction,EmpRegion as Region,Status from Training_TRNS where convert(varchar,DueDate,101) =convert(varchar,@DateFrom,101) END Else BEGIN select EmpName,convert(varchar,DueDate,101) as DueDate,SpeCourse_ID as CourseName, EmpJobFunction as JOBFunction,EmpRegion as Region,Status from Training_TRNS END END

    Read the article

  • SQL SERVER – Fix: Error : 402 The data types ntext and varchar are incompatible in the equal to operator

    - by pinaldave
    Some errors are very simple to understand but the solution of the same is not easy to figure out. Here is one of the similar errors where it clearly suggests where the problem is but does not tell what is the solution. Additionally, there are multiple solutions so developers often get confused with which one is correct and which one is not correct. Let us first recreate scenario and understand where the problem is. Let us run following USE Tempdb GO CREATE TABLE TestTable (ID INT, MyText NTEXT) GO SELECT ID, MyText FROM TestTable WHERE MyText = 'AnyText' GO DROP TABLE TestTable GO When you run above script it will give you following error. Msg 402, Level 16, State 1, Line 1 The data types ntext and varchar are incompatible in the equal to operator. One of the questions I often receive is that voucher is for sure compatible to equal to operator, then why does this error show up. Well, the answer is much simpler I think we have not understood the error message properly. Please see the image below. The next and varchar are not compatible when compared with each other using equal sign. Now let us change the data type on the right side of the string to nvarchar from varchar. To do that we will put N’ before the string. USE Tempdb GO CREATE TABLE TestTable (ID INT, MyText NTEXT) GO SELECT ID, MyText FROM TestTable WHERE MyText = N'AnyText' GO DROP TABLE TestTable GO When you run above script it will give following error. Msg 402, Level 16, State 1, Line 1 The data types ntext and nvarchar are incompatible in the equal to operator. You can see that error message also suggests that now we are comparing next to nvarchar. Now as we have understood the error properly, let us see various solutions to the above problem. Solution 1: Convert the data types to match with each other using CONVERT function. Change the datatype of the MyText to nvarchar. SELECT ID, MyText FROM TestTable WHERE CONVERT(NVARCHAR(MAX), MyText) = N'AnyText' GO Solution 2: Convert the data type of columns from NTEXT to NVARCHAR(MAX) (TEXT to VARCHAR(MAX) ALTER TABLE TestTable ALTER COLUMN MyText NVARCHAR(MAX) GO Now you can run the original query again and it will work fine. Solution 3: Using LIKE command instead of Equal to command. SELECT ID, MyText FROM TestTable WHERE MyText LIKE 'AnyText' GO Well, any of the three of the solutions will work. Here is my suggestion if you can change the column data type from ntext or text to nvarchar or varchar, you should follow that path as text and ntext datatypes are marked as deprecated. All developers any way to change the deprecated data types in future, it will be a good idea to change them right early. If due to any reason you can not convert the original column use Solution 1 for temporary fix. Solution 3 is the not the best solution and use it as a last option. Did I miss any other method? If yes, please let me know and I will add the solution to original blog post with due credit. Reference: Pinal Dave (http://blog.sqlauthority.com) Filed under: PostADay, SQL, SQL Authority, SQL Error Messages, SQL Query, SQL Server, SQL Tips and Tricks, T SQL, Technology

    Read the article

  • Fastest way to remove non-numeric characters from a VARCHAR in SQL Server

    - by Dan Herbert
    I'm writing an import utility that is using phone numbers as a unique key within the import. I need to check that the phone number does not already exist in my DB. The problem is that phone numbers in the DB could have things like dashes and parenthesis and possibly other things. I wrote a function to remove these things, the problem is that it is slow and with thousands of records in my DB and thousands of records to import at once, this process can be unacceptably slow. I've already made the phone number column an index. I tried using the script from this post: http://stackoverflow.com/questions/52315/t-sql-trim-nbsp-and-other-non-alphanumeric-characters But that didn't speed it up any. Is there a faster way to remove non-numeric characters? Something that can perform well when 10,000 to 100,000 records have to be compared. Whatever is done needs to perform fast. Update Given what people responded with, I think I'm going to have to clean the fields before I run the import utility. To answer the question of what I'm writing the import utility in, it is a C# app. I'm comparing BIGINT to BIGINT now, with no need to alter DB data and I'm still taking a performance hit with a very small set of data (about 2000 records). Could comparing BIGINT to BIGINT be slowing things down? I've optimized the code side of my app as much as I can (removed regexes, removed unneccessary DB calls). Although I can't isolate SQL as the source of the problem anymore, I still feel like it is.

    Read the article

  • PostgreSQL - can't save items - "type integer but expression is of type character"

    - by user984621
    I am getting still over and over again this error, the column age has the type integer, I am saving into this column integer-value, I also tried to don't save nothing into this column, but still getting this error... Could anyone help me, how to fix that? PG::Error: ERROR: column "age" is of type integer but expression is of type character varying at character 102 HINT: You will need to rewrite or cast the expression. : INSERT INTO "user_details" ("created_at", "age", "updated_at", "user_id") VALUES ($1, $2, $3, $4) RETURNING "id"

    Read the article

  • ON DELETE RESTRICT Causing Error 150

    - by Levi Hackwith
    CREATE TABLE project ( id INTEGER NOT NULL AUTO_INCREMENT, created_at DATETIME NOT NULL, name VARCHAR(75) NOT NULL, description LONGTEXT NOT NULL, is_active TINYINT NOT NULL DEFAULT '1', PRIMARY KEY (id), INDEX(name, created_at) ) ENGINE = INNODB; CREATE TABLE role ( id INTEGER NOT NULL, name VARCHAR(50) NOT NULL, description LONGTEXT NOT NULL, PRIMARY KEY (id) ) ENGINE = INNODB; CREATE TABLE organization ( id INTEGER NOT NULL AUTO_INCREMENT, created_at DATETIME NOT NULL, name VARCHAR(100) NOT NULL, is_active TINYINT NOT NULL DEFAULT '1', PRIMARY KEY (id) ) ENGINE = INNODB; CREATE TABLE user ( id INTEGER NOT NULL AUTO_INCREMENT, created_at DATETIME NOT NULL, role_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, last_login_at DATETIME NOT NULL, last_ip_address VARCHAR(25) NOT NULL, username VARCHAR(45) NOT NULL, password CHAR(32) NOT NULL, email_address VARCHAR(255) NOT NULL, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, address_1 VARCHAR(100) NOT NULL, address_2 VARCHAR(25) NULL, city VARCHAR(25) NOT NULL, state CHAR(2) NOT NULL, zip_code VARCHAR(10) NOT NULL, primary_phone_number VARCHAR(10) NOT NULL, secondary_phone_number VARCHAR(10) NOT NULL, is_primary_organization_contact TINYINT NOT NULL DEFAULT '0', is_active TINYINT NOT NULL DEFAULT '1', PRIMARY KEY (id), CONSTRAINT fk_user_role_id FOREIGN KEY (role_id) REFERENCES role (id) ON UPDATE RESTRICT ON DELETE RESTRICT, CONSTRAINT fk_user_organization_id FOREIGN KEY (organization_id) REFERENCES organization (id) ON UPDATE RESTRICT ON DELETE RESTRICT ) ENGINE = INNODB; CREATE TABLE project_user ( user_id INTEGER NOT NULL, project_id INTEGER NOT NULL, PRIMARY KEY (user_id, project_id), CONSTRAINT fk_project_user_user_id FOREIGN KEY (user_id) REFERENCES user (id) ON UPDATE RESTRICT ON DELETE CASCADE, CONSTRAINT fk_project_user_project_id FOREIGN KEY (project_id) REFERENCES project (id) ON UPDATE RESTRICT ON DELETE RESTRICT ) ENGINE = INNODB; CREATE TABLE ticket_category ( id INTEGER NOT NULL AUTO_INCREMENT, name VARCHAR(20) NOT NULL, description LONGTEXT NOT NULL, PRIMARY KEY (id) ) ENGINE = INNODB; CREATE TABLE ticket_type ( id INTEGER NOT NULL AUTO_INCREMENT, name VARCHAR(20) NOT NULL, description LONGTEXT NOT NULL, PRIMARY KEY (id) ) ENGINE = INNODB; CREATE TABLE ticket_status ( id INTEGER NOT NULL AUTO_INCREMENT, name VARCHAR(20) NOT NULL, description LONGTEXT NOT NULL, PRIMARY KEY (id) ) ENGINE = INNODB; CREATE TABLE ticket ( id INTEGER NOT NULL AUTO_INCREMENT, created_at DATETIME NOT NULL, project_id INTEGER NOT NULL, created_by INTEGER NOT NULL, submitted_by INTEGER NOT NULL, assigned_to INTEGER NULL, category_id INTEGER NOT NULL, type_id INTEGER NOT NULL, title VARCHAR(75) NOT NULL, description LONGTEXT NOT NULL, contact_type_id TINYINT NOT NULL, affects_all_clients TINYINT NOT NULL DEFAULT '0', is_billable TINYINT NOT NULL DEFAULT '1', esimated_hours DECIMAL(4, 1) NOT NULL DEFAULT '0', hours_worked DECIMAL (4, 1) NOT NULL DEFAULT '0', status_id TINYINT NOT NULL, PRIMARY KEY (id), CONSTRAINT fk_ticket_project_id FOREIGN KEY (project_id) REFERENCES project (id) ON UPDATE RESTRICT ON DELETE RESTRICT, CONSTRAINT fk_ticket_created_by FOREIGN KEY (created_by) REFERENCES user (id) ON UPDATE RESTRICT ON DELETE RESTRICT, CONSTRAINT fk_ticket_submitted_by FOREIGN KEY (submitted_by) REFERENCES user (id) ON UPDATE RESTRICT ON DELETE RESTRICT, CONSTRAINT fk_ticket_assigned_to FOREIGN KEY (assigned_to) REFERENCES user (id) ON UPDATE RESTRICT ON DELETE RESTRICT, CONSTRAINT fk_ticket_category_id FOREIGN KEY (category_id) REFERENCES ticket_category (id) ON UPDATE RESTRICT ON DELETE RESTRICT, CONSTRAINT fk_ticket_type_id FOREIGN KEY (type_id) REFERENCES ticket_type (id) ON UPDATE RESTRICT ON DELETE RESTRICT, CONSTRAINT fk_ticket_status_id FOREIGN KEY (status_id) REFERENCES ticket_status (id) ON UPDATE RESTRICT ON DELETE RESTRICT ) ENGINE = INNODB; CREATE TABLE ticket_time_entry ( id INTEGER NOT NULL AUTO_INCREMENT, user_id INTEGER NOT NULL, ticket_id INTEGER NOT NULL, started_at DATETIME NOT NULL, ended_at DATETIME NOT NULL, PRIMARY KEY (id), CONSTRAINT fk_ticket_time_entry_user_id FOREIGN KEY (user_id) REFERENCES user (id) ON UPDATE RESTRICT ON DELETE RESTRICT, CONSTRAINT fk_ticket_time_entry_ticket_id FOREIGN KEY (ticket_id) REFERENCES ticket (id) ON UPDATE RESTRICT ON DELETE RESTRICT ) ENGINE = INNODB; The ticket table's create statement causes an error 150. I have no clue why. When I remove the ON DELETE RESTRICT statements from the table declaration, it works. Why is that?

    Read the article

  • Image insertion from SQL info

    - by user528057
    What does 'howard.jpg' do in the sql statement below & how do I insert the image into my android app? CREATE TABLE IF NOT EXISTS employee ( _id INTEGER PRIMARY KEY AUTOINCREMENT, firstName VARCHAR(50), lastName VARCHAR(50), title VARCHAR(50), department VARCHAR(50), managerId INTEGER, city VARCHAR(50), officePhone VARCHAR(30), cellPhone VARCHAR(30), email VARCHAR(30), picture VARCHAR(200)) INSERT INTO employee VALUES(1,'Ryan','Howard','Vice President, North East', 'Management', NULL, 'Scranton','570-999-8888','570-999-8887','[email protected]','howard.jpg')

    Read the article

  • mySQL search for a number in VARCHAR field

    - by sea_1987
    Hi There, I have a field in my database that contain comma seperated values these values are numbers, and I am trying to do a search and count the number of times that a number appears in that column throughout the column, $sql = "SELECT sector_id_csv, COUNT(sector_id_csv) as count FROM cv WHERE sector_id_csv LIKE '$sectorId'"; This seems slow and does not return any results, and I know the sector_id it is search exsists in the table.

    Read the article

  • How can I search for numbers in a varchar column

    - by dave
    I've got a simple nvarchar(25) column in an SQL database table. Most of the time, this field should contain alphanumeric text. However, due to operator error, there are many instances where it contains only a number. Can I do a simple search in SQL to identify these cases? That is, determine which rows in the table contain only digits in this column. As an extension, could I also search for those column values which contain only digits and a space and/or slash. In other languages (eg. Perl, Java) a regular expression would resolve this quickly and easily. But I haven't been able to find the equivalent in SQL.

    Read the article

  • Why does RIGHT(@foostr, 0) return NULL when @foostr is varchar(max)?

    - by bob-montgomery
    In SQL Server 2005 If I want to find the right-most one character of a varchar(max) variable, no problem: declare @foostr varchar(max) set @foostr = 'abcd' select right (@foostr, 1) ---- d If I want to find the right-most zero characters of a string literal, no problem: select right ('abcd', 0) ------------------ It returns an empty string. If I want to find the right-most zero characters of a varchar(10), no problem: declare @foostr varchar(10) set @foostr = 'abcd' select right (@foostr, 0) ---- It returns an empty string. If I want to find the right-most zero characters of a varchar(max), well: declare @foostr varchar(max) set @foostr = 'abcd' select right (@foostr, 0) ---- NULL It returns NULL. Why?

    Read the article

  • Mass update of data in sql from int to varchar

    - by Christopher Kelly
    we have a large table (5608782 rows and growing) that has 3 columns Zip1,Zip2, distance all columns are currently int, we would like to convert this table to use varchars for international usage but need to do a mass import into the new table convert zip < 5 digits to 0 padded varchars 123 becomes 00123 etc. is there a way to do this short of looping over each row and doing the translation programmaticly?

    Read the article

  • Best indexing strategy for several varchar columns in Postgres

    - by Corey
    I have a table with 10 columns that need to be searchable (the table itself has about 20 columns). So the user will enter query criteria for at least one of the columns but possibly all ten. All non-empty criteria is then put into an AND condition Suppose the user provided non-empty criteria for column1 and column4 and column8 the query would be: select * from the_table where column1 like '%column1_query%' and column4 like '%column4_query%' and column8 like '%column8_query%' So my question is: am I better off creating 1 index with 10 columns? 10 indexes with 1 column each? Or do I need to find out what sets of columns are queried together frequently and create indexes for them (an index on cols 1,4 and 8 in the case above). If my understanding is correct a single index of 10 columns would only work effectively if all 10 columns are in the condition. Open to any suggestions here, additionally the rowcount of the table is only expected to be around 20-30K rows but I want to make sure any and all searches on the table are fast. Thanks!

    Read the article

  • Reasons for sticking with TEXT, NTEXT and IMAGE instead of (N)VARCHAR(max) and VARBINARY(max)

    - by John Assymptoth
    TEXT, NTEXT and IMAGE have been deprecated a long time ago and will, eventually, be removed from SQL Server. However, they are not going to be discontinued right away, not even in the next version of SQL Server, so it's not convenient for my enterprise to transform thousands of columns right away, even if it is using SQL Server 2012. What arguments can I use to postpone this migration? I know there are some advantages in using the new types. But I'm strictly looking for reasons not to migrate my data that is already functioning pretty well in the old types.

    Read the article

  • Ensuring uniqueness on a varchar greater than 255 in MYSQL/InnoDB

    - by Vijay Boyapati
    I have a table which contains HTML entries for news pages. When I initially designed it I used URL as the primary key. I've learned the error of my ways because left-joining is super slow. So I want to redesign the table with an integer (id) primary key, but still keep the rows unique based on the URL. The problem is that I've found URLs longer than 255 characters, and MySQL isn't letting my create a key on the URL. I'm using an InnoDB/UTF8 table. From what I understand it's using multiple bytes per character with a limit of 766 bytes for the key (in InnoDB). I would really love suggestions on an elegant way of keeping the rows unique based on URL, while using an integer primary key. Thanks!

    Read the article

  • how do I refactor this to make single function calls?

    - by stack.user.1
    I've been using this for a while updating mysql as needed. However I'm not too sure on the syntax..and need to migrate the sql to an array. Particulary the line database::query("CREATE TABLE $name($query)"); Does this translate to CREATE TABLE bookmark(name VARCHAR(64), url VARCHAR(256), tag VARCHAR(256), id INT) This is my ...guess. Is this correct? class table extends database { private function create($name, $query) { database::query("CREATE TABLE $name($query)"); } public function make($type) { switch ($type) { case "credentials": self::create('credentials', 'id INT NOT NULL AUTO_INCREMENT, flname VARCHAR(60), email VARCHAR(32), pass VARCHAR(40), PRIMARY KEY(id)'); break; case "booomark": self::create('boomark', 'name VARCHAR(64), url VARCHAR(256), tag VARCHAR(256), id INT'); break; case "tweet": self::create('tweet', 'time INT, fname VARCHAR(32), message VARCHAR(128), email VARCHAR(64)'); break; default: throw new Exception('Invalid Table Type'); } } }

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >